Вопрос

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