I am just starting to learn C, and have been reading a textbook by K.N. King about the programming language. In his chapter on Strings, he states that character arrays and character pointers are pretty much the same in terms of being passed into functions. However, they are not interchangeable, and one of the reasons behind this was that the characters in a character array can be modified, while a character pointer points to a string literal. However, earlier in his textbook he states that C stores string literals as an array of characters anyway, so would that not make the character pointers and character arrays the same?
Thank you in advance!
const char array_name[] = "string literal"in global array. This is just for a quick reference. Kindly go through the above links mentioned by others!char *(withoutconst) and modifying them is just undefined behavior, so compilers are free to put them in read-only memory, which most compilers do, but they're not required to.const char*atleast to my knowledge. Correct me if I'm wrongconst char *, but it isn't the case. Btw, a cast is always explicit in terms of the standard, you mean a conversion ... but there was never an implicit conversion removing aconstqualifier. The C standard just says writing to a string literal is undefined behavior. If you know your target system doesn't even know read-only memory, you can write to string literals (it's still UB of course)