Question 2
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a[] = {5, 6, 7, 8};
printf("%d %d %d\n", 2[a], *(a + 3), *a + 3);
return 0;
}
- A 7 8 8 Correct
- B 7 8 6
- C 6 7 8
- D Compilation error
Correct Answer: Option A
2[a] is *(2 + a) = a[2] = 7. *(a + 3) is a[3] = 8. *a + 3 takes a[0] (5) and adds 3 = 8 – the brackets make all the difference.
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!