• retagged by
23,573 views
38 38 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 _______

10 Answers

Best answer
54 54 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
14 14 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.

9 9 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$
3 3 votes
The program asks for what is the out put of printing ip[1] ,for that we need to understand what ip[1] represents here .it represents the second element of ip[ ] .What ip[ ] represents ? it represents arr[4] so what ip[1] will represent it will be arr[4+1] which is 6 .
Answer:
Position:
Show:

Related questions

41 41 votes
6 answers 6 answers
25.6k
25.6k views
Arjun asked Feb 7, 2019
25,642 views
Consider the following C program:#include <stdio.h int main() { float sum = 0.0, j=1.0, i=2.0; while (i/j 0.0625) { j=j+j; sum=sum+i/j; printf("%f\n", sum); } return 0; ...
44 44 votes
2 answers 2 answers
23.3k
23.3k views
Arjun asked Feb 7, 2019
23,333 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"...
107 107 votes
11 answers 11 answers
43.8k
43.8k views
Arjun asked Feb 7, 2019
43,798 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 the...
60 60 votes
8 answers 8 answers
38.9k
38.9k views
Kathleen asked Sep 15, 2014
38,925 views
Consider the following declaration of a two-dimensional array in C:char $a[100][100]$;Assuming that the main memory is byte-addressable and that the array is stored start...