歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> C++ const指針

C++ const指針

日期:2017/2/28 15:54:11   编辑:Linux教程

C++中的const指針聲明方式非常相似,平時很容易記混,今天差點弄錯了,特意把用法回顧總結一下。

const在*之前,表示內容不變
const char *p; //*p是const, p可變
char const *p; //*p是const, p可變

const在*之後,表示指針不變
char* const p; // p是const,*p可變

const在*前後都有,表示指針、內容均不變
const char* const p; //p和*p都是const

Copyright © Linux教程網 All Rights Reserved