假设我们有这样的声明:
int **const*** k;
然后,它可以很好地按字面翻译(根据 cdecl.org)为
declare k as pointer to pointer to pointer to const pointer to pointer to int
但是,我仍然不确定它不允许什么?它限制了哪些操作?我们还可以吗
(***k)++
也就是说,那里加const有什么作用?
还有...同样的问题
int *const**const* k;
这会带来什么不同?
谢谢!
最佳答案
still, I'm not sure to understand what it does not permit?
它不允许修改***k
指向的内容。
Could we still do
(***k)++
不。你不能。这是因为 ***K
是一个指向 const
指针的指针的指针,您无法修改它。但是,对 K
、*k
、**k
的修改是有效的。
为了方便起见,您可以这样理解:
int *const k; // k is a const pointer to integer. No modification to k.
int *const *k; // *k is a const pointer to integer. No modification to *k.
int *const **k; // **k is a const pointer to integer. No modification to **k.
int *const ***k; // ***k is a const pointer to integer. No modification to ***k.
int **const ***k; // ***k is a const pointer to integer. No modification to ***k.
关于c - 类型限定符(const)和复杂声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999692/