in C++ by (13.3k points)
0 like 0 dislike
5 views

Why is it common declare the function parameters with const modifier, when define function and especially when overloading operators in C++? What it mean?


  • c++ const modifier
  • c++ const function parameter

1 Answer

0 like 0 dislike
by (13.3k points)

The reason to make parameters const is to ensure that they are not changed by the function. This guarantees the caller of the function that the parameters they pass in will not be changed. Modifier const helps you from side effect-related changes of variable mucking up your data in situations where you might not expect it. It is very important in C++ type safety.

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.