If I declare an array of pointers like that:
char* arr[5] = {"Mercury",
"Mercury",
"Venus",
"Earth",
"EArth"};
Can I then change sings in those pointers? I have tried doing something like that
*(*(arr + 1) + 1) = 'i';
but it doesn't work, I get memory dump. Is there a way to do that or I have to declare it differently?
"Mercury"are string literals. Trying to modify a string literal results in undefined behaviour, most of the time a seg fault.*(*(arr + 1) + 1) = 'i';-->arr[1][1] = 'i';but it is still illegal codechar *tmp = arr[2]; arr[2] = arr[0]; arr[0] = tmp;would be fine. That would result in the ordering"Venus", "Mars", "Mercury", "Earth", "Pluto"