Hi,
I'm going through Learn Objective C on the Mac and came across this line of code:
const char *words[4] = { "aardvark", "abacus", "allude", "zygote"};
I understand pointers and indirection quite well, but the C syntax is still not clear to me.
I think that
const char *word
would create a pointer to a constant.
And I think that
const char *words[]
would tell the compiler to make a pointer to an array of constants.
So why put the index 4 in the brackets? If I run the test program without the number 4 it still runs, but that may just be luck.
Does this code
const char *words[4]
create an array of four addresses pointing to four items?
Or does it create one address with some information telling it that it points to four items?
Thanks.
I'm going through Learn Objective C on the Mac and came across this line of code:
const char *words[4] = { "aardvark", "abacus", "allude", "zygote"};
I understand pointers and indirection quite well, but the C syntax is still not clear to me.
I think that
const char *word
would create a pointer to a constant.
And I think that
const char *words[]
would tell the compiler to make a pointer to an array of constants.
So why put the index 4 in the brackets? If I run the test program without the number 4 it still runs, but that may just be luck.
Does this code
const char *words[4]
create an array of four addresses pointing to four items?
Or does it create one address with some information telling it that it points to four items?
Thanks.