ProgrammingModerateTCS NQT · C
What is printed?
What is printed?
int a[5] = {1, 2};
printf("%d %d %zu", a[1], a[2], sizeof a / sizeof a[0]);- A. 2 0 2
- B. 2 garbage value 5
- C. 1 0 5
- D. 2 0 5
Correct answer: D. 2 0 5
A partial initialiser zero-fills the remaining elements, so a[2] is 0; sizeof a / sizeof a[0] is the element count, 5.
More C Programming questions
- What is printed? c printf("%.1f %d", 7 / 2 2.0, (int)(7 / 2.0 2));
- What is printed? c printf("%d %d", 6 & 3 << 1, ~5 + 1);
- What is printed? c int n = 2, s = 0; switch (n) { case 1: s += 1; case 2: s += 2; case 3: s += 3; break; default: s += 9; } printf("%d", s);
- What is printed? c int a[] = {10, 20, 30, 40}; int p = a + 1; printf("%d %d %d", (p + 1), p[-1], (int)(&a[3] - p));
- What is printed? c char s[] = "hello"; s[2] = '0'; printf("%zu %zu %s", sizeof s, strlen(s), s + 3);
- What is printed? c unsigned char c = 200; c += 100; printf("%d", c);