ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int arr[2 * 3 + 1];
    printf("%zu", sizeof arr / sizeof arr[0]);
}
  1. A. 28
  2. B. 8
  3. C. 0
  4. D. 7

Correct answer: D. 7

2 * 3 + 1 = 7 is an integer constant expression, and sizeof arr / sizeof arr[0] counts elements, not bytes. 28 is sizeof arr alone with a 4-byte int, 8 reads the size as 2 * (3 + 1), and 0 divides the other way round.

More C Programming questions

Exams that ask this topic