What is the result of the following pointer arithmetic in C?<br>int arr[5] = {1, 2, 3, 4, 5};<br>int *ptr = arr;</br></br>printf("%d", *(ptr+2));</br>
18 views
- 1
- 2
- 3 (Correct Answer)
- 4
Explanation
Correct answer: c) 3
Explanation: Pointer arithmetic in C is used to manipulate the addresses of variables. In this case, the pointer variable ptr is assigned the address of the first element in the array arr. When we add 2 to the value of ptr using the + operator, the result is the address of the third element in the array. The value of this element is 3, so the output of the program is 3.