我無法找到C和C++語言中聲明中使用const的方式的直觀模式。下面是一些例子:瞭解「const」在聲明中的位置
const int a; //Const integer
int const a; //Const integer
const int * a; //Pointer to constant integer
int * const a; //Const pointer to an integer
int const * a const; //Const pointer to a const integer
在1,2線,似乎const
來臨之前或之後int
,這是它修改。
- 那麼如何,在第4行,該編譯器決定
const
正在修改*
(指針),而不是int
? - 編譯器遵循什麼規則來決定
const
適用於哪個事物? - 它是否遵循相同的規則
*
?
強制性鏈接到[順時針螺旋規則](http://c-faq.com/decl/spiral.anderson.html) –
如果沒有涉及數組或函數,只需**從右向左讀* *也可以提供幫助:'int const * const a':''a'是一個const const指針「。 –
馬克,如果您提交了答案,我會檢查它。非常有用,真的幫我弄明白了! –