Use const variables as function parameters when poThis tip submitted by beyonddc on 2006-01-28 23:47:39. It has been viewed 17237 times.
Rating of 4.9 with 118 votes
Use const variable as function parameter whenever is possible.
foo(const char *value)
*value = 10; // Error, because it is a constant.
The reason you want to pass a const variable into a function is to guarantee the function is not able to change the value that the pointer is pointing at.
It also helps readability because by reading the pass-in parameter of the function, you knew that the const char *value will not change.
Help your fellow programmers! Add a tip!