error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
#include<iostream>usingnamespacestd;intmain(){int*myballs=8;cout<<"myballsare"<<*myba...
#include <iostream>
using namespace std;
int main()
{
int* myballs=8;
cout<<"my balls are"<<*myballs<<endl;
cout<<"adrress is:"<<myballs<<endl;
*myballs=*myballs+1;
cout<<"now,my balls are:"<<*myballs<<endl;
cin.get();
return 0;
}
编译时提示
error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
bianliang.obj - 1 error(s), 0 warning(s)
若把int* myballs=8;改为
int *myballs;
*myballs=8;
则编译时候提示 warning C4700: local variable 'myballs' used without having been initialized
bianliang.obj - 0 error(s), 0 warning(s)
能通过编译,但是运行不了,
我用的时vista系统
microsoft visual C++ 6.0
急求解决办法,谢谢 展开
using namespace std;
int main()
{
int* myballs=8;
cout<<"my balls are"<<*myballs<<endl;
cout<<"adrress is:"<<myballs<<endl;
*myballs=*myballs+1;
cout<<"now,my balls are:"<<*myballs<<endl;
cin.get();
return 0;
}
编译时提示
error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
bianliang.obj - 1 error(s), 0 warning(s)
若把int* myballs=8;改为
int *myballs;
*myballs=8;
则编译时候提示 warning C4700: local variable 'myballs' used without having been initialized
bianliang.obj - 0 error(s), 0 warning(s)
能通过编译,但是运行不了,
我用的时vista系统
microsoft visual C++ 6.0
急求解决办法,谢谢 展开
2个回答
展开全部
不能转换 int类型为int指针类型
int a = 9 ; //ok
int *pa = &a; //ok
int *pa = 9 ;//error C2440
int *pa;
*pa = 8 ; //errorC4700
C4700 错误中 *pa 没有实际的指向位置,所以不能赋值
int *pa ;
int a;
pa = &a;
*pa = 1234; //ok
int a = 9 ; //ok
int *pa = &a; //ok
int *pa = 9 ;//error C2440
int *pa;
*pa = 8 ; //errorC4700
C4700 错误中 *pa 没有实际的指向位置,所以不能赋值
int *pa ;
int a;
pa = &a;
*pa = 1234; //ok
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
修改如下:
#include <iostream>
using namespace std;
int main()
{
int * myballs=NULL;
int a=8;
myballs=&a;
cout<<"my balls are "<<*myballs<<endl;
cout<<"adrress is:"<<myballs<<endl;
*myballs=*myballs+1;
cout<<"now,my balls are:"<<*myballs<<endl;
cin.get();
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int * myballs=NULL;
int a=8;
myballs=&a;
cout<<"my balls are "<<*myballs<<endl;
cout<<"adrress is:"<<myballs<<endl;
*myballs=*myballs+1;
cout<<"now,my balls are:"<<*myballs<<endl;
cin.get();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |