ProgrammingHardProduct company OA

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int a[4] = {1, 2, 3, 4};
char *c = (char *)a;
int *p = (int *)(c + 8);
printf("%d %td", *p, p - a);
  1. A. 2 2
  2. B. 3 2
  3. C. 9 2
  4. D. 3 8

Correct answer: B. 3 2

Moving a char pointer by 8 moves 8 bytes, which is two ints, so p points at a[2] = 3. p − a counts ints, giving 2. '8' mixes the byte offset into the int-pointer difference.

More C Programming questions

Exams that ask this topic