const 是constant的縮寫,只要有變量前面用const修飾,就意味着該變量裏面的數據是readonly。const可以修飾基本類型,構造類型,指針,等。
const int a = 10;//去掉int a 的值不變
int const a = 10;//去掉int a的值不變;
const int a[10] = {0};//去掉int 數組裏的內容不變
const int *p;//去掉類型int const 修飾p ;p所指向空間裏的內容不變
int* const p;//去掉類型int* p裏的內容不變,(p所指向的地址不變)
const struct node n[5];//去掉類型struct node ,n[5]裏的內容不變
struct node const *n[5];//去掉類型struct node ,n[5]裏每個元素所指向的空間裏的內容不變