const int x=3; int y=&x; 错误
int x=3; const int y=&x; 正确
权限大的接收权限小的是错误的
权限小的接收权限大的是正确的
看const用法技巧可以先忽略类型看const所指的后面
典型例子
①int x=3; const int &y=x;//x=10;正确//y=20;错误,不能改变y的值
②const int x=3;x=5;错误
③int x=3; const int y=x;y=5;错误
④int x=3;const int y=&x;y=5;错误
⑤int x=3,z=4;int *const y=&x;y=&z;错误
⑥const int x=3; const int &y=x;y=5;错误
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦