c语言数组特殊初始化方法

 C语言的常规初始化方法,我就很少说了,今天分享一下我以前看到的一种能够为指定位置赋值的方法。ide

 

int arr[10] = {0,1,2,3}; // 这种你们都很常见把it

 

可是这种呢class

int arr[10] = {[1]=1, [3]=3, [2]=2}; // 位置能够随意指定date

这样就至关于a[1] = 1, a[2] = 2, a[3] = 3方法

在此mark一下分享

相似的还有结构体的初始化语言

 

struct date {di

int day,view

int month,vi

int year};

 

struct date aDate = {.day=1, .year=2000, .month=1};  // 注意顺序

相关文章
相关标签/搜索