But I'm confused if that's actually the correct way to do it. Basically, with the code above, you're saying, "I'm going to have 13 pointers to a character" so:
months[ 0 ] points to, "J"
months[ 1 ] points to, "F"
months[ 2 ] points to, "M"
ect...
But how does the array know how long each C-style string is? Isn't it writing into un-allocated memory? I told the array that I'd be supplying 13 pointers to a char, but I didn't tell the array how long each of those entries was going to be, ya know?
Is the above code sample the correct way of doing it?
The string counterpart would be:
string months[ 13 ] = { "Jan", ect...};
but I'd like to be more familiar with c-style strings and arrays of c-style strings.
When the compiler encounters a string literal ("Jan", "Feb", etc), it allocates a char array in the read-only static storage of your program (in this case, array of size 4), which is populated with these characters {'J', 'a', 'n', '\0'}, etc, before the program starts executing.
The pointers you stored in months are pointing at the initial characters of those static arrays.