C String manipulation pointer vs array notation -


this question has answer here:

why first version make program crash, while second 1 doesn't? aren't same thing?

pointer notation

char *shift = "mondo"; shift[3] = shift[2]; 

array notation

char shift[] = {'m', 'o', 'n', 'd', 'o', '\0'}; shift[3] = shift[2]; 

mwe

int main( void ) {     char *shift = "mondo";     shift[3] = shift[2];      char shift[] = {'m', 'o', 'n', 'd', 'o', '\0'};     shift[3] = shift[2];      return 0; } 

no! 1 of important issues in c. in first, create pointer read-only part of memory, i.e. can not change it, read it. second, makes array of characters, i.e. part of memory of continuous characters can have both read , write access, meaning can both read , change values of array.


Comments