retagged by
28,313 views
110 votes
110 votes

What is the output of the following C code? Assume that the address of $x$ is $2000$ (in decimal) and an integer requires four bytes of memory.

int main () { 
         unsigned int x [4] [3] = 
         {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
         printf ("%u, %u, %u", x + 3, *(x + 3), *(x + 2) + 3); 
}
  1. $2036, 2036, 2036$
  2. $2012, 4, 2204$
  3. $2036, 10, 10$
  4. $2012, 4, 6$
retagged by

6 Answers

3 votes
3 votes
Explanation supporting *(x+3) = 2036

• int A[m][n];
• We can think of A[0] as the address of row 0, A[1] as the address of row 1  
• In general: A[i][j] = *(A[i] + j) = *(*(A+i)+j)
• Example: A[0][2] = *(A[0] + 2)
 
  o Note that: A[0] = *A
• Hence, if A is a 2D int array, we can think of A as a pointer to a pointer to an integer. That is, int**

Hence *(x+3) would return 2036.
0 votes
0 votes

This image may help to visualise, sorry for bad lighting 

Pro trick :- To access 1 dimensional array element need one * asterisk

 

For 2d - ** two asterisk

For 3d -- *** three asterisk

 

 

Answer:

Related questions

48 votes
48 votes
8 answers
3
go_editor asked Feb 14, 2015
16,317 views
Consider the following C program segment.# include <stdio.h int main() { char s1[7] = "1234", *p; p = s1 + 2; *p = '0'; printf("%s", s1); }What will be printed by the pro...
43 votes
43 votes
2 answers
4
go_editor asked Sep 29, 2014
20,439 views
What does the following fragment of C program print?char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p );$\text{GATE2011}$$\text{E2011}$$2011$$011$