in Programming edited by
194 views
3 votes
3 votes

Assume starting addresses of array arrop and twoD are $1000$ and $2000$ respectively. Also, assume that addresses are of $8$ bytes and integers are of $4$ bytes.

What will be value of *pp[1] after the last line (pp++) of the following program?

int main()
{
    int **pp;
    int *arrop[3];
    int twoD[3][3] = {{1,2,3}, {7,8,9}, {4,5,6}};
    pp = arrop;
    arrop[0] = (int *)(twoD+2);
    arrop[1] = (int *)(twoD+1);
    arrop[2] = (int *)(twoD);
    pp++;
}
in Programming edited by
194 views

1 Answer

10 votes
10 votes
2000 2004 2008
1 2 3
2012 2016 2020
7 8 9
2024 2028 2032
4 5 6

This is 3x3 array, twoD with respective addresses of each element.

twoD when used in expression works as if it was a pointer to int array of 3 elements. Therefore, twoD = 2000, twoD+1 = 2012 and twoD+2 = 2024.

arrop is a array of 3 elements storing integer pointer. arrop when used in expression works as if it was a pointer to an integer. Therefore, arrop = 1000.

1000 1008 1016
2024 2012 2000

This is 1x3 array, arrop with respective addresses of each element.

pp is a pointer to an integer pointer having value (pointing to) 1000.

when we do pp++ the value of pp becomes 1000 + 1 * sizeof(int *) = 1008.

Now, *pp[1] will be **(pp+1) = **(1008+8) = **(1016) = *(2000) = 1.

(Refer to above tables)

1 comment

Main point of this question : *pp[1] is equal to **(pp + 1)

1
1
Answer:

Related questions