For below sample code;
char* g_commands[]={
"abcd",
NULL
};
int main()
{
g_commands[1] = "efg";
char ** tmp = &g_commands[0];
for(; *tmp != NULL; tmp++){
printf("%s", *tmp);
}
return 0;
}
since tmp is pointing to the pointers in g_commands array in a loop, after I assign "efg" to g_commands[1], I expect the loop create a segmentation fault since the last element of g_commands is not null anymore. But the program finishes without exception and prints abcdefg successfully.
Why is it so? Does the compiler add NULL to the end of char* array as well?