I’m a little bit confused about this expression:
char *s = "abc";
Does the string literal get created on the stack?
I know that this expression
char *s = (char *)malloc(10 * sizeof(char));
allocates memory on the heap and this expression
char s[] = "abc";
allocates memory on the stack, but I’m totally unsure what the first expression does.
Typically, the string literal
"abc"is stored in a read only part of the executable. The pointerswould be created on the stack(or placed in a register, or just optimized away) – and point to that string literal which lives “elsewhere”.