How is this const being used?

const char *str in a parameter declaration indicates that the function will not try to modify the values that the str pointer points to. This means that you can call the function with a constant string. If you don’t have const in the declaration, it means that the function might modify the string, so you can only call it with writable strings.

As an example, a function like strcpy() declares has const on the second parameter (the source string), but not on the first parameter (the destination). It can (and usually does) modify the destination, but not the source.

Leave a Comment