This came up in another questions comment
String literals have static storage duration (see standard 6.4.5/6). – Jean-Baptiste Yunès
And I didn't want to hijack the comment section for this. So the question is when I do this:
char arr[10] = "Hello";
Do I actually have two strings in my memory?
One at arr
until my scope ends (auto duration)
and one at the point where ever the literal was created until the program closes (static duration)
Would this be equivalent to this:
char* str = "Hello";
char arr[10];
memcpy(arr,str,6);
If this is true, then I want to make sure what happens with
char a = 'a';
Does this also have double allocation? I would have guessed 'a'
would be written directly to a
Resulting in my last question would this be more memory efficient?
char arr[10] = { 'H', 'e', 'l', 'l', 'o', '\0'}