Q:

how const keyword works in c

I want to know about const internals in c and c++ . How compiler imposes constantness ?
Can some one help me please.

A:

In general const is 100% compiler. When you declare something const, the compiler places restrictions on what it will let you write. It won't let you assign to const scalar, assign through a const reference or or pointer, or invoke a non-const function of const object.
There is no guarantee that the compiler will arrange any sort of runtime protection.

A:

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.

A:

In addition to the compile-time enforced immutability provided by using the const keyword that other answers to your question have already mentioned, using it sometimes allows the compiler to place such data in the read-only section of a binary and memory.  According to Section 2.4.2 "Forever const" in Ulrich Drepper's article How To Write Shared Libraries doing so potentially allows programs to (1) use less resources and (2) start up faster.
Note that casting away the constness of data in such read-only areas of memory results in the undefined behavior, as usual.

