Sail E0 Webinar

MCQs

Total Questions : 28 | Page 3 of 3 pages
Question 21.

Which error you are likely to get when you run the following program?


#include<stdio.h>
main()
{
struct emp
{
char name[20];
float sal;
}
struct emp e[10];
int i;
for(i=0;i
  1.    suspecious pointer conversion
  2.    Floating point formats not linked
  3.    Cannot use scanf for strutures
  4.    Strings cannot be nested inside structures
 Discuss Question
Answer: Option B. -> Floating point formats not linked



Question 22.


What will be output of the following ?


#include<stdio.h>
#include<math.h>
int main()
{
printf("%f\n", sqrt(36.0));
return 0;
}
  1.    6.0
  2.    6
  3.    6.0000
  4.    Some absurd result
 Discuss Question
Answer: Option C. -> 6.0000


printf("%f`setminus`n", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).



Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the

 given number.



Question 23.

Binary equivalent of 5.375 is


  1.    101.101110111
  2.    101.011
  3.    101011
  4.    none of these
 Discuss Question
Answer: Option B. -> 101.011


Question 24.

What will be output of the following?

#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("Cn");
else
printf("C++n");
return 0;
}


  1.    C
  2.    C++
  3.    Error
  4.    None of the above
 Discuss Question
Answer: Option A. -> C

if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'

#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10fn",0.7, a);
return 0;
}

Output:
0.7000000000 0.6999999881


Question 25.

If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program?


#include<stdio.h>
int main()
{
float a =5.375;
char *p;
int i;
p = (char*)&a;
for(i=0;i<=3;i++)
printf("%02x", (unsigned char)p[i]);
return 0;
}


  1.    40 AC 00 00
  2.    04 CA 00 00
  3.    00 00 AC 40
  4.    00 00 CA 04
 Discuss Question
Answer: Option C. -> 00 00 AC 40


Question 26.

A float occupies 4 bytes. if the hexadecimal equivalent of each of these bytes is A,B,C and D, then when this float is stored in memory, these bytes get stored in the order


  1.    ABCD
  2.    DCBA
  3.    0xABCD
  4.    0xDCBA
 Discuss Question
Answer: Option B. -> DCBA



Question 27.

We want to round off x, a float to an int value. The correct way to do so would be


  1.    y=(int)(x+0.5)
  2.    y=int(x+0.5)
  3.    y=(int)x+0.5
  4.    y=(int)(x+0.5)
 Discuss Question
Answer: Option A. -> y=(int)(x+0.5)


Question 28.

What will be output of the program ?


#include<stdio.h>
#include<math.h>
int main()
{
printf("%d, %d, %dn", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
return 0;
}


  1.    4, 4, 4
  2.    4, 8, 8
  3.    4, 8, 10
  4.    4, 8, 12
 Discuss Question
Answer: Option C. -> 4, 8, 10


sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.



sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.



sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.


Note: If you run the above program in Linux platform (GCC
Compiler) it will give 4, 8, 12 as output. If you run in Windows
platform (TurboC Compiler) it will give 4, 8, 10 as output. Because, C
is a machine dependent language.



Latest Videos

Latest Test Papers