Everything is fine in your code.
char *str = "Hello World!";
OK, you declare a char * , pointing to the litteral line. To be true, you must write const char *str = because the litteral string is an immutable string ( str[4] = 'u'; will be incorrect)
str = "Reassign str.";
Ok, the str pointer now points to another litteral line. The same observation as above, it must be const.
char *str2 = "Something.";
Another story
str = strdup(str2);
Now str points to the string malloc'ed. For the first time, it is true that str will not be const. str[0] = 's'; will be right here.
free(str);
Ok, you free the line highlighted by strdup .
exit(EXIT_SUCCESS);
You perfectly return the setpoint (0) to the environment.
Serge Ballesta
source share