开发者

C: Is this type of initialization correct?

开发者 https://www.devze.com 2022-12-17 20:52 出处:网络
int startingPoint[2]={i,j}; I got this after reading an online code.Is this correct? Means if values of i an开发者_运维技巧d j can be changed at runtime before this statement, will this initialize t
int startingPoint[2]={i,j};

I got this after reading an online code.Is this correct? Means if values of i an开发者_运维技巧d j can be changed at runtime before this statement, will this initialize the array with the correct values? Please explain.


This works in C99 but not in C89.


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};
0

精彩评论

暂无评论...
验证码 换一张
取 消