🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C Pointers: all 10 questions

Quiz: C Pointers · Question 7 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int a[] = {10, 20, 30, 40, 50};
    int *p = &a[1], *q = &a[4];
    printf("%d %d\n", (int)(q - p), *q - *p);
    return 0;
}
  1. A.12 30
  2. B.3 30
  3. C.3 3
  4. D.4 40
Answer & explanation

Correct answer: 3 30

Subtracting two pointers into the same array gives the number of elements between them (4 - 1 = 3), not bytes; 50 - 20 = 30.

Can you get the rest right without peeking?

Take the timed Quiz: C Pointers quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →