1.
char string[] = "String literal";
string[0] = '[';
everything compiles; then seg fault.
2.
char* string1 = "String literal"
string1[0] = '[';
printf("%c\n", string1[0]);
compiles; prints
3.
char *p = "ab" ; // string literal, stores in read-only
char p[] = "ab"; //can be manipulated
char *p = (char []){'a', 'b', '\0'};
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes
http://stackoverflow.com/questions/30533439/string-literals-vs-array-of-char-when-initializing-a-pointer
compilers replace string literals wtih pointers.
No comments:
Post a Comment