in Programming
1,097 views
1 vote
1 vote

The value returned by the following code is _____

int foo()
{
    int a[] = { 10, 20, 30, 40, 50, 60 };
    int *p = &a[1] , *q = &a[5] ;
    return q-p;
}
in Programming
by
1.1k views

1 comment

@Arjun Sir plz explain this.
0
0

5 Answers

0 votes
0 votes

Answer : 4

lets assume 10 stored at address = 100 ,

its array so continuous memory allocation . 

lets assume integer size = 4 Byte

then , 

10 20 30 40 50 60

100                    104                  108               112               116                120

p = (a+1) = 104  ,  q= (a+5) = 120

q-p = (120-104) = 16

we assumed size of INT = 4 Byte , so divide it by 4

so, q-p = 16/4 = 4

Answer:

Related questions