ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: B. 4

Pointer subtraction counts elements, and a + 4 is four elements past a[0].

More C Programming questions

Exams that ask this topic