What will the following code snippet output? int arr[5] = {1, 2, 3, 4, 5};…
2025
What will the following code snippet output?
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", 2[arr]);
- A.
Syntax Error
- B.
1
- C.
2
- D.
3
Attempted by 914 students.
Show answer & explanation
Correct answer: D
In C, the syntax array[index] is actually syntactic sugar for *(array + index). Therefore, array[index] and index[array] are equivalent. In this question, 2[arr] is the same as arr[2]. It's just an unconventional way to access array elements. The third element of the array arr is 3, which is what this code will output.