ProgrammingVery hardProduct company OA

Assume 8-bit unsigned char. What is printed?

Assume 8-bit unsigned char. What is printed?
printf("%d %d %d", (int)-3.7, (unsigned char)-1, (int)(0.1 * 30));
  1. A. -4 255 3
  2. B. -3 255 3
  3. C. -3 255 2
  4. D. -3 -1 3

Correct answer: B. -3 255 3

Converting a floating value to int truncates toward zero, so −3.7 becomes −3, not −4. −1 converted to unsigned char wraps to 255. 0.1 × 30 is 3.0000000000000004 in binary floating point, which truncates to 3; if it had come out just below 3, it would have printed 2.

More C Programming questions

Exams that ask this topic