While initializing a const char array, I tried to change the string and I was able to change it without any issue.
I was learning how to initialize a const char array. I think I am doing some mistake here which I am not able to find.
int main(int argc, char const *argv[])
{
const char *strs[10];
strs[0] = "wwww.google.com";
printf("%s\n", strs[0]);
strs[1] = "https://wwww.google.com";
strs[0] = "ss";
printf("%s\n", strs[0]);
return 0;
}
Output:
1st init: wwww.google.com
2nd init: ss -> Here, I expect it to throw error
1st init. Nah, the pointers are default initialized first. And then you assign for a second time with"wwww.google.com".const char *strs[10];definesstrsas an array of ten pointers to constant characters. The array itself isn't constant, and neither is it an array of characters.