Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 46

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 85

Answer:

main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u %u %u %d \n”,a,*a,**a,***a);
printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
}


Answer:
100, 100, 100, 2
114, 104, 102, 3


Explanation:
The given array is a 3-D one. It can also be viewed as a 1-D array.
-----------------------------------------------
| 2 | 4 | 7 | 8 | 3 | 4 | 2 | 2 | 2 | 3 | 3 | 4 |
-----------------------------------------------
100 102 104 106 108 110 112 114 116 118 120 122

thus, for the first printf statement a, *a, **a give address of first element . since the indirection ***a gives the value. Hence, the first line of the output.
for the second printf a+1 increases in the third dimension thus points to value at 114, *a+1 increments in second dimension thus points to 104, **a +1 increments the first dimension thus points to 102 and ***a+1 first gets the value at first location and then increments it by 1. Hence, the output.

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 46 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: