ProgrammingHardGATE CS · TCS NQT

What is printed? Assume int is 4 bytes.

What is printed? Assume int is 4 bytes.
#include <stdio.h>
int main(void) {
    int i = 1;
    size_t n = sizeof(i++);
    printf("%d %zu", i, n);
}
  1. A. 1 1
  2. B. 2 4
  3. C. 1 4
  4. D. 2 1

Correct answer: C. 1 4

The operand of sizeof is not evaluated, so i stays 1, while sizeof(int) is 4. Expecting the increment to happen is the usual trap.

More C Programming questions

Exams that ask this topic