ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int i;
int a[5] = {0};
for (i = 0; i < 5; i++)
a[i] = i * i;
printf("%d", a[4] - a[2]);
}- A. 8
- B. 6
- C. 12
- D. 16
Correct answer: C. 12
a[4] = 16 and a[2] = 4, so the difference is 12. Index 4 is the last valid element of a five-element array.
More C Programming questions
- How many placements of 4 queens on a 4 by 4 board have no two queens attacking each other? The program counts them by backtracking. What…
- What is printed? c #include <stdio.h> int der(int n) { if (n == 0) return 1; if (n == 1) return 0; return (n - 1) (der(n - 1) + der(n…
- How many subsets of {1, 2, 3, 4, 5} sum to 6? Compute with this recursive program. c #include <stdio.h> int v[5] = {1, 2, 3, 4, 5}; int…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t x = 0x1C; int c = 0; for (int i…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 3, r = 0; for (int i = 0; i < 4; i++) { r = (r << 1) | (x & 1u); x >>=…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xABCD, p = 0; while (x) { p ^= x & 1u; x >>= 1; } / p is the parity…