ProgrammingVery hardProduct company OA · GATE CS
What is printed?
What is printed?
const char *w[] = {"red", "green", "blue", "cyan"};
const char **p[] = {w + 2, w, w + 3, w + 1};
const char ***q = p;
printf("%s ", **q);
printf("%s ", *(*++q + 1));
printf("%c", **q[1]);- A. red green c
- B. blue green c
- C. blue red c
- D. blue green b
Correct answer: B. blue green c
**q is *p[0] = w[2] = "blue". ++q moves q to p + 1, so *q = p[1] = w, and *(w + 1) = "green". Now q[1] is p[2] = w + 3; one * gives "cyan" and the second gives 'c'. 'red' forgets the + 1 after the increment.
More C Programming questions
- What is printed? c int m(int n) { return n > 100 ? n - 10 : m(m(n + 11)); } int main(void) { printf("%d %d", m(50), m(105)); }
- What is printed? c int h(unsigned a, unsigned b) { int c = 0; for (unsigned x = a ^ b; x; x >>= 1) c += x & 1; return c; } int main(void)…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = &a[3]; printf("%d %d %d", p[-2], -1[p], (p - 1)[-1]);
- What is printed? c struct C { int r, g, b; } c = {.b = 9, .r = 4}; printf("%d %d %d", c.r, c.g, c.b);
- Assume 4-byte int with 4-byte alignment. What is printed? c union U { char c[5]; int i; }; printf("%zu", sizeof(union U));
- Compiled as C99 or later, what is printed? c int i = 1; for (int i = 5; i < 7; i++) { int i = 10; printf("%d ", i); } printf("%d", i);