I have the following function declaration:
void fn(int);
This function has one integral type. Now I could call this function the transfer of not a const or const-integral object. In any case, this function is going to copy the object into its local int parameter. Therefore, any changes to this parameter will be local to the function and will not affect the actual arguments of the caller. Now my question is, in which scenario will I declare that this single int parameter is of type const? I do not see the need to declare this function as follows.
void fn(const int);
This is due to the fact that the arguments will in any case be passed by value, and this function in no way can change the arguments in any case. I understand that by declaring a parameter constant, a function cannot change it inside its body. However, there are no drawbacks, even if the function changes, since the parameter is local to the function.
source
share