Multiple choice technology programming languages

What is the output of following code snippet ? void main() { int arr[5]={10,20,30,40,50}; printf("%d",(arr+2)); }

  1. 30

  2. 20

  3. syntax error

  4. garbage

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

(arr+2) evaluates to the memory address of arr[2], not the value 30 at that location. Using %d to print an address produces an arbitrary large number that appears as garbage. To print the value, use *(arr+2) or arr[2].