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]);
  1. A. red green c
  2. B. blue green c
  3. C. blue red c
  4. 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

Exams that ask this topic