c+ 小问题,有提示

[复制链接]
查看11 | 回复4 | 2011-2-8 22:13:50 | 显示全部楼层 |阅读模式
#include
using namespace std;
int main()
{

const int a=10;

int p=&a;



cout<<*p<<endl;
}
提示:
5.c: In function ‘int main()’:
5.c:6: error: invalid conversion from ‘const int*’ to ‘int’
5.c:8: error: invalid type argument of ‘unary *’

回复

使用道具 举报

千问 | 2011-2-8 22:13:50 | 显示全部楼层
int a=10;
int * p;
p = &a;两点问题: 1.const 常量不能付给int
2.&a是地址,赋值给p,p是地址,不能是int 型
3.还有最好在最后加return 0;因为是int main(),要反回值的。
回复

使用道具 举报

千问 | 2011-2-8 22:13:50 | 显示全部楼层
int a[2][3]=,};是初始化a[0][0]=123a[1][0]=456a[0][1]没有初始化啊就是0哈
回复

使用道具 举报

千问 | 2011-2-8 22:13:50 | 显示全部楼层
修改程序如下:#include using namespace std;int main(){
const int a=10;
const int *p=&a;
cout<<*p<<endl;
return 0;}
回复

使用道具 举报

千问 | 2011-2-8 22:13:50 | 显示全部楼层
int main() 改void main()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行