ProgrammingHardProduct company OA

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int *p = (int[]){10, 20, 30};
p[1] += 5;
printf("%d %zu", p[1] + p[2], sizeof((int[]){10, 20, 30}) / sizeof(int));
  1. A. 55 1
  2. B. 55 2
  3. C. 55 3
  4. D. 50 3

Correct answer: C. 55 3

A compound literal (C99) creates an unnamed, modifiable array; p points to its first element, so p[1] becomes 25 and 25 + 30 = 55. sizeof applied to the compound literal itself sees an array of 3 ints (12 bytes), not a pointer, giving 3.

More C Programming questions

Exams that ask this topic