I’m having trouble understanding the following code:
const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"}
I don’t understand what is stored in the array suit, are they pointers? And if so, where are the strings stored?
Also, is the pointer constant, or the array constant?
I would appreciate a full detailed explanation of this code, and what is going on in memory!
Thanks in advance.
We learn a lot by using cdecl.org. This is what it tells us about
suit:So:
char(in this case, the first character of each string).const, and neither is the array.The strings are literals; where they are stored is implementation-specific.
In ASCII art:
Note that
suititself is not a pointer; it’s the name of the array.