Say we have such declaration :

int **const*** k;

Then, it could be well translated literally (according to cdecl.org) to

declare k as pointer to pointer to pointer to const pointer to pointer to int

However, still, I'm not sure to understand what it does not permit? Which operation does it restrict? Could we still do

(***k)++

In other words, what is the effect of adding const there?

And... Same question for

int *const**const* k;

Which difference would it make?

Thanks!

有帮助吗?

解决方案

still, I'm not sure to understand what it does not permit?

It does not permit the modification that ***k points to.

Could we still do

(***k)++   

No. You can't. This is because ***K is a pointer to pointer to pointer to const pointer and you can't modify it. But yes, modification to K, *k, **k is valid.

For the sake of convenience, you can understand this as follows:

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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top