ProgrammingHardProduct company OA
What is printed?
What is printed?
for (int k = 0; k < 3; k++) {
static int s[3];
int a[3] = {0};
s[k] = a[k] = k + 1;
printf("%d%d ", s[0] + s[1] + s[2], a[0] + a[1] + a[2]);
}- A. 11 32 33
- B. 11 32 63
- C. 11 22 33
- D. 11 33 66
Correct answer: B. 11 32 63
The static array is created once and keeps earlier writes: its sums are 1, 3, 6. The automatic array is re-created and zeroed on every pass, so it holds only the current element: 1, 2, 3. Each pass prints the two sums side by side.
More C Programming questions
- Assume ASCII. What is printed? c const char s = "pointer"; printf("%c%c%c", s + 1, s[s - 'o' + 2], (s + strlen(s) - 1) - 1);
- With int a = 3, b = 7; which of these statements compile as C (not C++)? c (a > b ? &a : &b) = 0; / (i) / (a > b ? a : b) = 0; / (ii) / a…
- What is printed? c int f(int n) { static int depth = 0; depth++; if (n <= 1) return depth; int a = f(n - 1); int b = f(n - 2); return a +…
- What is printed? c char s[] = "hello world"; char p = strchr(s, 'o'), q = strrchr(s, 'o'); q = '0'; printf("%s %zu %td", s, strlen(p), q…
- What is printed? c unsigned p = 0xB5; p ^= p >> 4; p ^= p >> 2; p ^= p >> 1; printf("%u", p & 1);
- Assume 2-byte short, 4-byte int and natural alignment. What is printed? c #include <stddef.h> struct R { char a; short b; char c; int d…