4 ms·
There's another error here: The qualifier const can be added to the left of a variable or parameter type If you have the declaration char* str; Adding con
by pmjordan 14y ago
There's another error here:
The qualifier const can be added to the left of a variable or parameter type
If you have the declaration
char* str;
Adding const to the left of the type doesn't make the variable immutable:
const char* str;
This indicates that str will point to a character or string which must not be mutated. str itself can be reassigned. To make str immutable, you need
char* const str; // immutable pointer to mutable string
or
const char* const str; // immutable pointer to immutable string
Const does tend to be used little in pure C, though you pretty much can't escape it in C++ code. (I also use it a lot in C, and have type warnings/errors cranked up to max)