ProgrammingHardGATE CS

What is printed? Assume int occupies 4 bytes.

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

Correct answer: C. 8 5

The operand of sizeof is not evaluated (unless it is a variable-length array), so neither i++ nor i = 100 happens. Each expression has type int (4 bytes): n = 8 and i is still 5.

More C Programming questions

Exams that ask this topic