日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

const char*, char const* and char *const 的

系統(tǒng) 1883 0



constchar*,charconst*,char*const的區(qū)別問(wèn)題幾乎是C++面試中每次都會(huì)有的題目。

事實(shí)上這個(gè)概念誰(shuí)都有只是三種聲明方式非常相似很容易記混。
Bjarne在他的TheC++ProgrammingLanguage里面給出過(guò)一個(gè)助記的方法:
把一個(gè)聲明從右向左讀。

char*constcp;(*讀成pointerto
cpisaconstpointertochar

constchar*p;
pisapointertoconstchar;

charconst*p;
同上因?yàn)镃++里面沒(méi)有const*的運(yùn)算符,所以const只能屬于前面的類型。


C++標(biāo)準(zhǔn)規(guī)定,const關(guān)鍵字放在類型或變量名之前等價(jià)的。
constintn=5;
//sameasbelowintconstm=10;


constint*p;//sameasbelow
const(int)*pintconst*q;//(int)const*p


char**p1;
//pointertopointertochar
constchar**p2;
//pointertopointertoconstchar
char*const*p3;
//pointertoconstpointertochar
constchar*const*p4;
//pointertoconstpointertoconstchar
char**constp5;
//constpointertopointertochar
constchar**constp6;
//constpointertopointertoconstchar
char*const*constp7;
//constpointertoconstpointertochar
constchar*const*constp8;
//constpointertoconstpointertoconstchar

const char*, char const* and char *const 的區(qū)別


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 白玉县| 凌源市| 广宗县| 大姚县| 淮阳县| 卢湾区| 巴塘县| 永嘉县| 自贡市| 昆明市| 巴中市| 敦煌市| 大理市| 怀化市| 德州市| 聊城市| 通榆县| 盐山县| 丹东市| 都兰县| 博湖县| 微山县| 锦州市| 阆中市| 赤峰市| 凯里市| 温州市| 广汉市| 精河县| 顺义区| 崇阳县| 龙里县| 城步| 东乌珠穆沁旗| 天水市| 阳城县| 鹤壁市| 清苑县| 化德县| 西城区| 八宿县|