ProgrammingEasyHCL · Tech Mahindra pattern
What is printed?
What is printed?
int a[5] = {1, 2};
printf("%d", a[3]);- A. 2
- B. Compilation error
- C. 0
- D. A garbage value
Correct answer: C. 0
When an array has an initialiser list shorter than its size, the remaining elements are set to 0. So a = {1, 2, 0, 0, 0} and a[3] is 0, even for a local array.
More C Programming questions
- What is printed? c int x = 5; printf("%d", x > 3 ? x < 10 ? 1 : 2 : 3);
- What is printed? c int i; for (i = 0; i < 10; i += 3) printf("%d ", i);
- What is printed? c int x = 10; int p = &x; int q = &p; q = 20; printf("%d", x);
- What is printed? c char s[20] = "Code"; strcat(s, "Hub"); printf("%zu", strlen(s));
- What is printed on a two's-complement machine? c printf("%d", ~5);
- What is printed by a C99 (or later) compiler? c printf("%d %d", -7 / 2, -7 % 2);