ProgrammingVery hardProduct company OA

Assume 4-byte int. What is printed?

Assume 4-byte int. What is printed?
printf("%d %d", sizeof(int) * -1 < 0, (int)sizeof(int) * -1 < 0);
  1. A. 0 1
  2. B. 0 0
  3. C. 1 1
  4. D. 1 0

Correct answer: A. 0 1

sizeof yields an unsigned size_t, so −1 is converted to size_t and the product is a huge positive number, never below 0. The cast binds tighter than *, so (int)sizeof(int) is the int 4 and 4 × −1 = −4 < 0 is true.

More C Programming questions

Exams that ask this topic