[英]pointer to 2d array
I have the following code: 我有以下代码:
int arr[2][2][2]={10,3,4,5,6,7,8,9};
int *p;
printf("%u",arr);
p=(int *)arr;
printf("%u",p);
Which outputs 哪个输出
64166
64164
But I would think that p
and arr
point to the same memory address. 但是我认为
p
和arr
指向相同的内存地址。 Why are different addresses shown? 为什么显示不同的地址?
Let's walk through the code 让我们看一下代码
int *p;
printf("%u",p);
p is an unitialized int pointer. p是单元化的int指针。 It is going to print out whatever is in memory.
它会打印出内存中的所有内容。
p=(int *)arr;
printf("%u",p);
p now is pointing to the address of the array in memory, and prints that address. p现在指向内存中数组的地址,并打印该地址。
But same code 但是相同的代码
#include <stdio.h>
int main()
{
int arr[2][2][2]={10,3,4,5,6,7,8,9};
int *p;
printf("\n%u",arr);
p=(int *)arr;
printf("\n%u\n",p);
return 0;
}
gives same result only. 仅给出相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.