What is the use of const keyword in functions?

I have seen a lot of examples where const is used instead of only declaring a constant variable.....so how does the const keyword function there.
For example:
1
2
 virtual const char* what() const
{}

also:
 
void print(const int n) {}


what happens in the above codes if const is not used and what is the effect produced due to the usage of const keyword?
Last edited on
The use of const is always the same: The const object cannot be modified [without tricks like const_cast or mutable]

mutable:
http://en.cppreference.com/w/cpp/keyword/mutable


const_cast:
http://en.cppreference.com/w/cpp/language/const_cast


In case of a function, const can only be used with a member function. In that case the const prevents the modification of the member variables of this object.
Last edited on
closed account (48T7M4Gy)
const means constant, can't be changed, read-only
Topic archived. No new replies allowed.