Question 2
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a[] = {10, 20, 30, 40, 50};
int *p = a;
p += 2;
printf("%d %d\n", *p, *(p + 1));
return 0;
}
- A 12 13
- B 30 40 Correct
- C 20 30
- D 30 31
Correct Answer: Option B
p starts at a[0]. p += 2 moves it two elements to a[2] (30), and *(p + 1) is a[3] (40). Pointer arithmetic counts elements, not bytes.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!