I want to know about const internals in c and c++ . How compiler imposes constantness ? Can some one help me please.
const keyword in C and C++ has two different semantic meanings.
(1) It can declare the constness of an object
const SomeType t;
In the above case object t is a non-modifiable object. The compiler will do its best to prevent you from modifying it by observing the const-correctness rules (which are not the same in C and C++). The const-correctness rules are enforced only conceptually, at the language level, which means that there are ways to circumvent these rules, and which also means that constness of an object will not be necessarily implemented at physical level. I.e. there's no guarantee that the object will be ultimately placed in read-only memory.
It is important to note that this kind of constness is not removable in a sense that any attempts to modify the above object by casting away the constness lead to undefined behavior (excluding possible mutable members in C++).
(2) It can declare constness of an access path to an object
const SomeType *p;
The above p is declared as a pointer-to-const. This does not necessarily mean that the object p is pointing to is a constant object (as defined by the first kind of const above). It might easily be a non-constant one, in which case it is perfectly legal to cast away the constness from the above access path and modify the object, although it is generally not a good programming practice. In other words, constness of an access path is potentially removable.
Taking the above into account, the following declaration
const int* const* const* const p = 0;
includes two different kinds of const: the very last const declares the constness of the object p (first kind), while the rest of const declare the constness of various levels of access path represented by p (second kind).
P.S. As a [possibly unrelated] side note, it is probably worth noting that the term constant has drastically different meanings in C and C++. In C++ constants are objects declared as const. In C constants are literals. Objects declared as const are not constants in C terminology.