+ 6
What is the output of this code and how ?
void main() { static int a=2,b=4,c=5; static int *arr1[ 2]={&a,&b}; static int *arr2[ 2]={&b,&c}; int *((*arr[2])[2]={&arr1, &arr2}; printf("%d",*(*(**(arr+1)+1))); }
3 Answers
+ 4
thanks
+ 3
The answer is 5.
Consider that ** in pointer will point directly to the value.
First with *arr1[2] = {&a, &b}; and the arr2
The expression return same like you inserting normal array, but the different is, this is pointer, not just a normal array.
So now going to the *(*arr[2])[2] = {&arr1, &arr2};
Still with same concept with the first one, but this one is Double-Dimension array. Which will do {2, 4}, {4, 5}
And the last calling for arr.
**(arr+1) will be point to 4 on the first Dimension array where it contain {2, 4}. Why? arr+1 mean the location is +1. If you put arr without +1, it will point to 2. The next is another pointer outside scope, but we got the location of 4 inside the scope, the next, we jump to +1 on the back. The expression like that mean it change the pointing location. So It will goes to the same location as 4, but move to another dimension of array. As stated before, we got {2, 4} and {4, 5}. So the pointer move to location of 5, and we got the last pointer on the very front, which mean double pointer and the output will show 5
0
hello



