ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    char *w[] = {"ab", "cd", "ef"};
    char **p = w + 2;
    printf("%c%c", (*p)[0], p[-1][1]);
}
  1. A. ef
  2. B. ed
  3. C. cd
  4. D. fe

Correct answer: B. ed

p points at w[2], so (*p)[0] is e, and p[-1] is w[1] = "cd", whose second character is d. Mixing up the indexes gives fe or ef.

More C Programming questions

Exams that ask this topic