设有定义:int n=0; *p=&n; **q=&p;
A p=1
B *q=2
C q=p
D *p=5
希望知道的能把题目和答案分析清楚
欢迎大家解答!!!!!!
[此贴子已经被作者于2007-9-9 16:54:03编辑过]
第一次测试代码:
#include<stdio.h>
int main()
{
int n=0,*p=&n,**q=&p;
p=1;
*q=2;
q=p;
*p=5;
printf("%d\n",*p);
printf("%d\n",*q);
getchar();
return 0;
}
编译不通过:
C:\Documents and Settings\Administrator\桌面\未命名1.cpp: In function `int main()':
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:7: error: invalid conversion from `int' to `int*'
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:8: error: invalid conversion from `int' to `int*'
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:9: error: cannot convert `int*' to `int**' in assignment
第二次测试代码:
去掉 p=1;
编译不通过:
C:\Documents and Settings\Administrator\桌面\未命名1.cpp: In function `int main()':
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:8: error: invalid conversion from `int' to `int*'
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:9: error: cannot convert `int*' to `int**' in assignment
第三次测试代码:
去掉 *q=2;
编译不通过:
C:\Documents and Settings\Administrator\桌面\未命名1.cpp: In function `int main()':
C:\Documents and Settings\Administrator\桌面\未命名1.cpp:7: error: cannot convert `int*' to `int**' in assignment
第四次测试代码:
去掉 *q=2;
编译通过: