Sathyaish said:
Why do we declare some arguments as constant? Is it because we do not
expect the value of those constant arguments to change in the function?
More precisely, we want to make sure that
they are not [accidentally] changed in the function.
int f(const int i) {
i = 13; // error
return i + 1;
}
Your compiler should complain about this.
const
char* car(const char* s) {
return ('\0' == *s)? s: s + 1;
}
In this case, we want to prevent the function
from changing any of the characters in the string
which begins with the character to which s points.