104 views

Which of the following will print the value $2$ for this code snippet?

#include<stdio.h>
int main()
{
int arr[10][20][30] = {0};
arr[5][2][1] = 2;
__________    // missing line here
return 0;
}

The missing line above is:

1. printf("%d",*(((arr+5)+2)+1));
2. printf("%d",***((arr+5)+2)+1);

3. printf("%d",*(*(*(arr+5)+2)+1));
4. printf("%d", *(*((arr+5)+2)+1);


So *(arr+5) will be 6th element (as we start array from 0,1,2..) =600

now *(*(arr+5)+2) means 3rd element in array of address 600. Thus we get 602 here

Here i assumed int as 1 so 600+ 2*1 =602 but also even considering int=2 we get 604 (600,602,604,..) still index is 3rd in that array.(0,1,2..)

*(*(*arr+5)+2)+1) will take us to array at 602. Now we go till index 1 from zero and value here is 2 by

arr[5][2][1].

Hope everyone get this!

by

1
201 views