"bneha69" <[EMAIL PROTECTED]> wrote:
>
> Pointer array is a collection of addresses.
> 
> if I write in a function
> 
> int *arr[4];
> int i=2,j=5,k=7,l=9;
> arr[0]=&i;
> arr[1]=&j;
> arr[2]=&k;
> arr[3]=&l;
> //there is no problem in the above code.
> 
> But if I write
> int i=2,j=5,k=7,l=9;
> int *arr[4]={&i,&j,&k,&l};//errors-illegal initializtion
> 
> if I write
> 
> int a[]={1,2,3,4,5};
> int *p[]={a,a+1,a+2,a+3,a+4};//errors-illegal initialization
> 
> if I write
> static int a[]={1,2,3,4,5};
> static int *p[]={a,a+1,a+2,a+3,a+4};
> //there is no problem in this.
> 
> Does it mean that I can never initialize  a pointer
> array by the addresses of auto variables at the time
> of its declarion?

In C90 yes, in C99 no. C99 relaxed the restriction.
Unfortunately, there aren't many C99 conforming
compilers around.

> If yes then why is this rule made?

Historical I guess.

> Please explain the meaning of the error- illegal
> initialization.

It means you've done something illegal in the context
of C.

> I don't understand it properly.

Static duration objects require a constant expression
initialisors. In C90, aggregate object (struct, union
and array) initialisation requires constant expressions
too. The address of static duration object is a constant
expression. The address of non static duration objects
isn't.

-- 
Peter

Reply via email to