[Solved] changing strings in array of char pointers [closed]


The difference is:

names1 is declared simply as an array of string pointers without other defined characteristics. Using string literals here will put the string literals into a section in your executable file which is read-only, because the compiler can this way re-use them. For example, when you use char* a = "abc"; char* b = "abc"; then most likely a and b will have equal memory addresses as values. This means you can’t modify them, so you get a “Segmentation fault” (another name for the same error is “Access Violation”).

names2 is declared as an array of arrays of chars. Assigning a string literal there will copy the data of the strings into the array, and since there is no const thing in play in your code, the array has to be mutable, so in turn your strings stored in the char arrays are mutable as well.

solved changing strings in array of char pointers [closed]