nowonder
nowonder

Reputation: 335

C: Is this type of initialization correct?

int startingPoint[2]={i,j};

I got this after reading an online code.Is this correct? Means if values of i and j can be changed at runtime before this statement, will this initialize the array with the correct values? Please explain.

Upvotes: 3

Views: 154

Answers (2)

Prasoon Saurav
Prasoon Saurav

Reputation: 92854

int startingPoint[2]={i,j};
I got this after reading an online code.Is this correct?

Yes that is a correct C code(will work on all modern C compilers).However that wont work on a C89 compiler.

Means if values of i and j can be changed at runtime before this statement, will this initialize the array with the correct values?

Yes!

scanf("%d %d",i,j);
/* some code */

int abc[]={i,j};

Upvotes: 1

Peter Eisentraut
Peter Eisentraut

Reputation: 36719

This works in C99 but not in C89.

Upvotes: 8

Related Questions