I am reading the book Let us C by Yashavant Kanetkar.
In the Array of Pointers section there is a section of code which is giving me problems:
int main()
{
static int a[] = {0, 1, 2, 3, 4}; //-----------(MY PROBLEM)
int *p[] = {a, a+1, a+2, a+3, a+4};
printf("%u %u %d\n", p, *p, *(*p));
return 0;
}
What I don't understand is: Why has the array a have to be initialized as static? I tried initializing it without the static keyword, but I got an error saying "illegal".
staticmeansais specified to have static storage, so treated as a pointer it is a compile-time constant expression. Array (as an aggregate type) initializers in C90 require constant expressions.