I’m curious about string literals. I’ve read that in the case of something like this, const char * ptr = "Hello World"; that they have static storage duration in the data of the program and are not allocated on the heap or stack. What about when it is used as an argument?
for example
Function("panda");
when defined as
void Function(const char* str)
{
...
}
is "panda" now also included in the data of the program or is it allocated on the stack?
In your example, “panda” is (normally: implementation defined) stored with static duration in the data of the program.
When you call
Function("panda"), this is the same asextern char* s = "panda"; Function(s);. This is made more clear in your declaration for the function.Functiondoes not receive a char array, it receives a pointer to const chars. So the stack contains a pointer, not a char array.