ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
char *words[] = {"bat", "cat", "rat", "mat"};
char **p = words + 1;
char **q = words + 3;
printf("%ld", (long)(q - p));
  1. A. 2
  2. B. 16
  3. C. 4
  4. D. 1

Correct answer: A. 2

Pointer subtraction between two char** values yields the number of char* ELEMENTS between them, not bytes: q-p = (words+3)-(words+1) = 2.

More C Programming questions

Exams that ask this topic