• retagged by
23,834 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

1 1 vote
given :

*ip = (a + 4) = &(a[4])

ip = (a+4)

ip[1] = *(ip+1) = *( (a+4) +1 )

ip[1] = *(a+5) = a[5] = 6

 

correct me if i am wrong
0 0 votes

This is how I've solved

*ip=arr+4 (It is saying move 4 elements ahead and stop)

Techically: ip=arr(base address) + 4*size(each element)

From the perspective of ip: {5, 6, 7, 8, 9, 0, 1, 2, 5} ip is pointing 5

ip[1] Asked ip[1]=ip(address)+1*size(element)   6 is the answer

 

0 0 votes

This is how I've solved

*ip=arr+4 (It is saying move 4 elements ahead and stop)

Techically: ip=arr(base address) + 4*size(each element)

From the perspective of ip: {5, 6, 7, 8, 9, 0, 1, 2, 5} ip is pointing 5

ip[1] Asked ip[1]=ip(address)+1*size(element)   answer 6

 

Answer:
Position:
Show:

Related questions

41 41 votes
6 answers 6 answers
26.1k
26.1k views
Arjun asked Feb 7, 2019
26,121 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; ...
45 45 votes
2 answers 2 answers
23.5k
23.5k views
Arjun asked Feb 7, 2019
23,493 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"...
110 110 votes
12 answers 12 answers
44.6k
44.6k views
Arjun asked Feb 7, 2019
44,618 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
39.3k
39.3k views
Kathleen asked Sep 15, 2014
39,262 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...