Sail E0 Webinar

MCQs

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


What will be the output of the program?


#include<stdio.h>
int main()
{
float d=2.25;
printf("%e,", d);
printf("%f,", d);
printf("%g,", d);
printf("%lf", d);
return 0;
}
  1.    2.2, 2.50, 2.50, 2.5
  2.    2.2e, 2.25f, 2.00, 2.25
  3.    2.250000e+000, 2.250000, 2.25, 2.250000
  4.    Error
 Discuss Question
Answer: Option C. -> 2.250000e+000, 2.250000, 2.25, 2.250000

printf("%e,", d); Here '%e' specifies the "Scientific Notation" format. 

So, it prints the 2.25 as 2.250000e+000.

printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format. 

So, it prints the 2.25 as 2.250000.

printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the

 2.25 as 2.25.

printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints 

the 2.25 as 2.250000.


Question 2.


What will be the output of the program?


#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}
  1.    2.000000, 1.000000
  2.    1.500000, 1.500000
  3.    1.550000, 2.000000
  4.    1.000000, 2.000000
 Discuss Question
Answer: Option A. -> 2.000000, 1.000000

ceil(x) round up the given value. It finds the smallest integer not < x.
floor(x) round down the given value. It finds the smallest integer not > x.

printf("%f, %f`setminus`n", ceil(n), floor(n)); In this line ceil(1.54) round up the 1.54 to 2 

and floor(1.54) round down the 1.54 to 1.

In the printf("%f, %f`setminus`n", ceil(n), floor(n)); statement, the format specifier "%f %f" 

tells output to be float value. Hence it prints 2.000000 and 1.000000.



Question 3.


What will be the output of the program?


#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7f)
printf("C\n");
else
printf("C++\n");
return 0;
}
  1.    C
  2.    C++
  3.    Compiler error
  4.    Non of above
 Discuss Question
Answer: Option B. -> C++


if(a < 0.7f) here a is a float variable and 0.7f is a float constant.
The float variable a is not less than 0.7f float constant. But both
are equal. Hence the if condition is failed and it goes to else it
prints 'C++'
Example:


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


Output:
0.6999999881 0.6999999881


Question 4.


What will be the output of the program?


#include<stdio.h>
int main()
{
float f=43.20;
printf("%e, ", f);
printf("%f, ", f);
printf("%g", f);
return 0;
}
  1.    `4.320000e^(+01)`, 43.200001, 43.2
  2.    4.3, 43.22, 43.21
  3.    4.3e, 43.20f, 43.00
  4.    Error
 Discuss Question
Answer: Option A. -> `4.320000e^(+01)`, 43.200001, 43.2

printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So, 

it prints the 43.20 as 4.320000e+01.

printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So, 

it prints the 43.20 as 43.200001.

printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.

20 as 43.2.


Question 5.


What will be the output of the program?


#include<stdio.h>
#include<math.h>
int main()
{
printf("%d, %d, %d\n", 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.


Question 6.


What will be the output of the program?


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

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 7.


What will be the output of the program?


#include<stdio.h>
int main()
{
float *p;
printf("%d\n", sizeof(p));
return 0;
}
  1.    2 in 16bit compiler, 4 in 32bit compiler
  2.    4 in 16bit compiler, 2 in 32bit compiler
  3.    4 in 16bit compiler, 4 in 32bit compiler
  4.    2 in 16bit compiler, 2 in 32bit compiler
 Discuss Question
Answer: Option A. -> 2 in 16bit compiler, 4 in 32bit compiler

sizeof(x) returns the size of x in bytes.
float *p is a pointer to a float.

In 16 bit compiler, the pointer size is always 2 bytes.
In 32 bit compiler, the pointer size is always 4 bytes.


Question 8.


What will be the output of the program?


#include<stdio.h>
int main()
{
float fval=7.29;
printf("%d\n", (int)fval);
return 0;
}
  1.    0
  2.    0.0
  3.    7.0
  4.    7
 Discuss Question
Answer: Option D. -> 7

printf("%d`setminus`n", (int)fval); It prints '7'. because, we typecast the (int)fval in to integer. 

It converts the float value to the nearest integer value.



Question 9.


What will be the output of the program?


#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("C\n");
else
printf("C++\n");
return 0;
}
  1.    C
  2.    C++
  3.    Compiler error
  4.    Non of 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 %.10f\n",0.7, a);
return 0;
}


Output:
0.7000000000 0.6999999881


Question 10.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?


  1.    rem = (5.5 % 1.3)
  2.    rem = modf(5.5, 1.3)
  3.    rem = fmod(5.5, 1.3)
  4.    Error: we can't divide
 Discuss Question
Answer: Option C. -> rem = fmod(5.5, 1.3)


fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs
floating point divisions.
Example:


#include<stdio.h>
#include <math.h>
int main ()
{
printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
return 0;
}


Output:
fmod of 5.5 by 1.3 is 0.300000


Latest Videos

Latest Test Papers