ProgrammingHardIBM · Deloitte pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = 100;
int y = x / 3 * 3;
int z = x % 3;
printf("%d %d", y, z);
  1. A. 100 1
  2. B. 99 1
  3. C. 99 0
  4. D. 100 0

Correct answer: B. 99 1

Integer division truncates: 100/3 = 33 (dropping the remainder). 33*3 = 99, not 100 — multiplying back doesn't recover the original value because of that truncation. x%3 = 100 mod 3 = 1 (since 99 is the largest multiple of 3 not exceeding 100).

More C Programming questions

Exams that ask this topic