Pointers to Arrays

Below is the program i tried to execute......

main()
{
static int a[ ] = {0,1,2,3,4};
static int *p[ ] = {a, a+1, a+2, a+3, a+4};

printf (�\n %u %u %d�, p, *p, *(*p) );
}

This works, but i wanted to know why both a[ ] and *p[ ] are declared as "static". If we dont declare a[ ] as static then that gives me error, but if i dont declare *p[ ] as static then it works fine.
Tell me the significance of declaring them as "static".

Jay.

Depending on where in the program you do this
(inside or outside of a function) will affect
its' scope within the program. Declaring static
variables within a function allocates storage
for them and although local to the function,
they are only initialized once. Meaning, the next
time you call that function, they still contain
the resulting values they had after the last call
to that function. Declaring them in main()
however doesn't give you a good feel for that
since you would not normally do repeated calls
to main().

HI

Actually in Ansi version of c++ it is mandatory
to give static specifier during the declaration of an integer array to retain it's the contents during the execution of the program and the values are initialized only once .Without the static in the declaration the program produces unwanted and unexpected results.