Consider the following C program: #include <stdio.h> int main(){ int…
2019
Consider the following C program:
#include <stdio.h>
int main(){
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
printf(“%d\n”, ip[1]);
return 0;
}
The number that will be displayed on execution of the program is ___________ .
Attempted by 139 students.
Show answer & explanation
Correct answer: 6
Answer: 6
Explanation: The pointer arithmetic and array indexing determine which array element is accessed.
The array is arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 5}.
ip is set to arr + 4, so ip points to arr[4], which has the value 5.
ip[1] means the element one past what ip points to: *(ip + 1) which is arr[5], and arr[5] = 6.
Therefore the program prints 6.
A video solution is available for this question — log in and enroll to watch it.