Possible Duplicate:
Sell me on using const correctness
In C (and I guess C++ as well), is there any particular reason to declare a variable const
other than to prevent yourself from modifying it by mistake later on? Are const
variables treated differently at compile time other than the fact that they aren't allowed to be modified?
Edit: I understand the obvious optimizations that come from declaring a *ahem* constant as const
, and the whole const
method thing makes sense in C++, but how about declaring a function argument as const
in C?