ProgrammingVery hardProduct company OA

What is printed?

What is printed?
const char *w[] = {"heap", "stack", "queue", "trie"};
const char **p = w;
printf("%c", *++*p);
printf("%c", **++p);
printf("%c", *(*p + 3));
printf("%c", (*(p + 1))[4]);
printf(" %s %td", w[0], p - w);
  1. A. hsce heap 1
  2. B. esce heap 1
  3. C. etke eap 2
  4. D. esce eap 1

Correct answer: D. esce eap 1

*++*p increments the pointer STORED in w[0] (it now points at "eap") and reads 'e'. **++p moves p itself to w[1] and reads 's'. *(*p + 3) is the fourth character of "stack", 'c'; (*(p + 1))[4] is "queue"[4] = 'e'. w[0] was permanently advanced, so %s prints eap, and p − w = 1. The strings themselves are never modified – only pointers to them – so this is well defined.

More C Programming questions

Exams that ask this topic