int main() {
const int a=0;
char s[100];
sprintf(s,"%lld",&a);
int *p = (int*)atoll(s);
const int * q = &a;
*p =1;
cout<<a<<endl;
cout<<*p<<endl;
cout<<*q<<endl;
cout<<(&a == p)<<endl;
return 0;
}
以上程序输出是
0
1
1
1
这是为啥呢?
int main() {
const int a=0;
char s[100];
sprintf(s,"%lld",&a);
int *p = (int*)atoll(s);
const int * q = &a;
*p =1;
cout<<a<<endl;
cout<<*p<<endl;
cout<<*q<<endl;
cout<<(&a == p)<<endl;
return 0;
}
以上程序输出是
0
1
1
1
这是为啥呢?
本文标题:c++ const
本文链接:https://www.haomeiwen.com/subject/ccaymqtx.html
网友评论