for the following code I was wondering if there is just an array created in the stack or if there is also an array created in the static. I’m just kind of confused with array creation from a string.
char str[] = "White";
I’m assuming this creates a pointer in the stack called str which points to an array with the following contents, "White\0", in the static memory. Is this correct as an assumption?
Nope.
"White"is an array ofchar[6]in static memory somewhere. (or magic land, it’s not specified, and is completely irrelevant). Note that it may or may not be the same static array as another"White"elsewhere in the code.char str[] = "White";creates a new localchar[6]array on the stack, namedstr, and copies the characters from the static array to the local array. There are no pointers involved whatsoever.Note that this is just about the only case where an array can be copied. In most situations, arrays will not copy like this.
If you want a pointer to the magic static array, simply use
const char* str = "White";Phonetagger notes that if the line of code is not in a function, then
stris not on the stack, but also in the magic static memory, but the copy still (theoretically at least) happens just before execution begins of code in that translation unit.