edited by
197 views
0 votes
0 votes

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);
    
edited by

1 Answer

Best answer
3 votes
3 votes

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!

selected by
Answer:

Related questions

3 votes
3 votes
1 answer
1
Bikram asked May 14, 2017
392 views
Assume that $a[4]$ is a one-dimensional array of $4$ elements, $p$ is a pointer variable and $p = a$ is performed. Now, which among these expressions is illegal?$p == a[0...
0 votes
0 votes
1 answer
2
Bikram asked May 14, 2017
352 views
Spot the error(s) in this code snippet :int n=2; // Line 1 switch(n) { case 1.5: printf( "gate"); break; case 2: printf( "overflow"); break; case 'A': printf("gateoverflo...
0 votes
0 votes
1 answer
3
Bikram asked May 14, 2017
200 views
#include<stdio.h int K = 10; int main() { foo(); foo(); return 0; } int foo() { static int k= 1; printf("%d ",k); k++; return 0; }What is the output of the above code sni...
0 votes
0 votes
1 answer
4
Bikram asked May 14, 2017
203 views
What is the output of the following program? int fun (int z) { if( z==0 || z==1 ) return 1; else return fun(z-1) ; } int main() { int y; y=fun(8); printf(“%d”...