📜  门| GATE-CS-2015(套装1)|第 45 题

📅  最后修改于: 2021-09-27 06:07:56             🧑  作者: Mango

以下 C 代码的输出是什么?假设 x 的地址是 2000(十进制)并且一个整数需要四个字节的内存。

#include 
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);
}

(一) 2036、2036、2036
(B) 2012, 4, 2204
(C) 2036, 10, 10
(四) 2012, 4, 6答案:(一)
解释:

x = 2000

Since x is considered as a pointer to an 
array of 3 integers and an integer takes 4
bytes, value of x + 3 = 2000 + 3*3*4 = 2036

The expression, *(x + 3) also prints same 
address as x is 2D array.


The expression *(x + 2) + 3 = 2000 + 2*3*4 + 3*4
                            = 2036

这个问题的测验