ProgrammingHardProduct-company MCQ pattern

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int a[5];
printf("%td %td", (char *)(a + 1) - (char *)a,
                  (char *)(&a + 1) - (char *)a);
  1. A. 20 20
  2. B. 4 20
  3. C. 1 5
  4. D. 4 4

Correct answer: B. 4 20

a decays to int *, so a + 1 is one int (4 bytes) further. &a has type int (*)[5], a pointer to the whole array, so &a + 1 is 5 × 4 = 20 bytes further. Same address, different types.

More C Programming questions

Exams that ask this topic