ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
/* LP64: 4-byte int, 8-byte long, 4-byte float */
char c = 'a';
short s = 2;
printf("%zu %zu %zu %zu", sizeof(c), sizeof(c + c), sizeof(s * 2L), sizeof(c ? s : 1.0f));
  1. A. 1 1 8 2
  2. B. 1 4 8 4
  3. C. 1 4 4 4
  4. D. 1 4 8 2

Correct answer: B. 1 4 8 4

sizeof looks only at the TYPE of the expression. c + c promotes both chars to int, so it is 4. s * 2L converts s to long, so 8 on LP64. The conditional operator's result type comes from both branches after the usual arithmetic conversions — short and float give float (4) — regardless of which branch would be taken.

More C Programming questions

Exams that ask this topic