ProgrammingVery hardProduct company OA

What is printed?

What is printed?
_Bool b = 0.5;
printf("%d %d", b + 2, (_Bool)256);
  1. A. 2.5 1
  2. B. 3 1
  3. C. 2 0
  4. D. 3 0

Correct answer: B. 3 1

Converting any non-zero scalar to _Bool gives 1 and zero gives 0, with no truncation: 0.5 becomes 1, so b + 2 = 3. (_Bool)256 is also 1. An 8-bit unsigned char would have turned 256 into 0, which is the trap.

More C Programming questions

Exams that ask this topic