When an identifier is declared to be const, no writes are allowed to it.
When reading a const declaration, read backwards:
y = "hello"; // legal, pointer is not const
*y = '\0'; // illegal, changes contents
z = "hello"; // illegal, changes pointer
*z = '\0'; // legal, contents are not const
const enforces a certain form of type-safety. If some piece of memory isn't meant to be changed in a given scope, declare it to be const and the compiler will help you ensure that it isn't inadvertently written to.
const is mostly a defensive programming method. It can also act as a hint to the compiler to perform certain optimizations, but this happens rarely.
copyright © 2004, 2005 Emil Mikulic