ProgrammingHardGATE CS · TCS NQT

What is printed? Assume int is 4 bytes.

What is printed? Assume int is 4 bytes.
#include <stdio.h>
int main(void) {
    int a[4];
    printf("%ld", (long)((char *)&a[2] - (char *)&a[0]));
}
  1. A. 4
  2. B. 8
  3. C. 2
  4. D. 12

Correct answer: B. 8

Two ints apart is 2 * 4 = 8 bytes, which is the character-pointer difference.

More C Programming questions

Exams that ask this topic