ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
char *w[] = {"red", "green", "blue"};
char **p = w + 1;
printf("%c %s %c %zu", **p, *(p + 1) + 2, *(*(p - 1) + 1),
       strlen(p[1]) - strlen(*w));
  1. A. g ue r 1
  2. B. g ue e 1
  3. C. r ue e 1
  4. D. g lue e 1

Correct answer: B. g ue e 1

p points at w[1] ("green"), so **p is 'g'. *(p + 1) is w[2] = "blue"; adding 2 skips two characters, printing "ue". *(p − 1) is w[0] = "red" and +1 selects 'e'. strlen("blue") − strlen("red") is 1 (both are size_t, and 4 − 3 does not wrap).

More C Programming questions

Exams that ask this topic