Best practices with c strings -> char a[] vs char *b

@joel, geesh, I should know better than explain stuff late at night. What was meant was that amessage and pmessage will behave similarly in the context of the example.

I always like to code with explicit definitions wherever possible when I share code. The example of char *foo = "a const string" is an example of a (variable) pointer pointing to an implicit const (aka immutable) string. However, const char foo[] = "a const string" explicitly declares foo` a immutable pointer to an immutable string. To many readers, I believe this is clearer.

However, in both cases and due to the nature of C pointers, one can easily index outside of the const foo array or anywhere in memory with char *foo pointer. Pointers can be cruel :frowning_face:

1 Like