Sail E0 Webinar

MCQs

Total Questions : 15 | Page 2 of 2 pages
Question 11. What is the output of this C code?
int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
  1.    128
  2.    - 128
  3.    Depends on the compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> - 128


signed char will be a negative number.
Output:
$ cc pgm2.c
$ a.out
-128


Question 12. Comment on the output of this C code?
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf("equal\n");
else
printf("not equal\n");
}
  1.    equal
  2.    not equal
  3.    Output depends on compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> equal


0.1f results in 0.1 to be stored in floating point representations.
Output:
$ cc pgm5.c
$ a.out
equal


Question 13. Comment on the output of this C code?
int main()
{
char c;
int i = 0;
FILE *file;
file = fopen("test.txt", "w+");
fprintf(file, "%c", 'a');
fprintf(file, "%c", -1);
fprintf(file, "%c", 'b');
fclose(file);
file = fopen("test.txt", "r");
while ((c = fgetc(file)) != -1)
printf("%c", c);
return 0;
}
  1.    a
  2.    Infinite loop
  3.    Depends on what fgetc returns
  4.    Depends on the compiler
 Discuss Question
Answer: Option A. -> a


None.
Output:
$ cc pgm3.c
$ a.out
a


Question 14. Comment on the output of this C code?
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal\n");
else
printf("not equal\n");
}
  1.    equal
  2.    not equal
  3.    Output depends on compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> not equal


0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ a.out
not equal


Question 15. What is short int in C programming?
  1.    Basic data type of C
  2.    Qualifier
  3.    short is the qualifier and int is the basic datatype
  4.    All of the mentioned.
 Discuss Question
Answer: Option C. -> short is the qualifier and int is the basic datatype


None.


Latest Videos

Latest Test Papers