retagged by
13,408 views
14 votes
14 votes

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 _______

retagged by

6 Answers

Best answer
26 votes
26 votes
$6$
ip is an integer pointer and the initial assignment sets it to the element at array index $4$ i.e. $5$.(holds address of ar index $4$)
The next statement refers to the next integer after it which is $6 (ip[1]=*(ip+1))$.
edited by
8 votes
8 votes
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5} , *ip = arr+4;

printf("%d\n",ip[1]);

ip is an integer pointer that is currently holding the address where 5 is stored.(i.e. a[4])

ip[1] = *(ip+1) = value present at the next address i.e. 6. so it will print 6.

5 votes
5 votes
arr+0 points to the 1st element of the array(index 0) which is 1.

Hence arr+4 will point to the 5th element of the array(index 4) which is 5.

As per assignment $*ip=arr+4$ , $ip[0]=5$

Hence $ip[1]=6$
Answer:

Related questions

21 votes
21 votes
3 answers
1
18 votes
18 votes
2 answers
2
Arjun asked Feb 7, 2019
15,348 views
Consider the following C program:#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; int i, sum=0, *b=a+4; for (i=0; i<5; i++) sum=sum+(*b-i)-*(b-i); printf("%d\n"...
13 votes
13 votes
4 answers
3
Arjun asked Feb 7, 2019
9,562 views
Consider the following C program :#include<stdio.h int jumble(int x, int y){ x = 2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d \n"...
59 votes
59 votes
9 answers
4
Arjun asked Feb 7, 2019
27,036 views
Consider the following C program:#include <stdio.h int r() { static int num=7; return num ; } int main() { for (r();r();r()) printf(“%d”,r()); return 0; }Which one of...