← 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;
}
- A.12 30
- B.3 30
- C.3 3
- 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 →