注册 登录
编程论坛 新人交流区

关于数组和指针的问题

不是我的 发布于 2007-10-08 15:42, 477 次点击

int* p;
int **pp;
int arr[100];
p=arr; //正确
pp = &arr; //错误

printf("a1=%p,a2=%p\n",arr,&arr); //而打印arr和&arr的结果都一样?

谁能解释一下&arr到底是什么吗?而为什么打印出的结果一样呢?

3 回复
#2
moximon2007-10-09 20:51
arr是数组的指针,指向首元素地址...
#3
qq34121552007-10-09 21:05

--------------------Configuration: Text1 - Win32 Debug--------------------
Compiling...
Text1.cpp
C:\Documents and Settings\superSS\桌面\Text1.cpp(9) : error C2440: '=' : cannot convert from 'int (*)[100]' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.

Text1.exe - 1 error(s), 0 warning(s)

根本不能运行啊,LZ怎么输出???

#4
qq34121552007-10-09 21:05
如果是&a[0]那就相当与a
1