Originally Posted by
itCbitC
so what do you think is the type of fruit[0]
the compiler auto adds a NULL to the end of (const char* type) arrays so no need to do so explicitly.
Do you mean to say that this:
Code:
char * fruit[] = {"apple", "pear", "orange", "grape", "banana"};
actually looks this way:
Code:
char * fruit[] = {"apple", "pear", "orange", "grape", "banana", NULL};
I would say not. Try this:
Code:
char * fruit[] = {"apple", "pear", "orange", "grape", "banana"};
char * veg[] = { "tomato", "cabbage", "celery" };
char *dummy[] = { NULL };
int main()
{
char **ptr = fruit;
while(*ptr)
{
printf("%s is a fruit\n", *ptr);
ptr++;
}
}
You'd sure to see tomato, cabbage and celery printed as fruits.
A character array in double quotes, where there is no fixed size, will have a NUL-character at the end. But any other arrays will have nothing more in them than what you put there - unless you specify a size, and it is an initalized array, the rest of the array is filled with zeros.
--
Mats