前⾯我们说过,结构体的变量在内存中是顺序存储的,基于这⼀点就可以初始化结构体定义的⼆维数组对象,并检验这个事情。#include<iostream> using namespace std;
typedef struct
{
uint8_t a;
uint8_t b[10];
uint8_t c[3];
}basic;
int main()
{
苏州蚕桑专科学校basic array[][4]=
{
{1,0,0},
{2,0,0},
{3,0,0,0,1},
{2,2,1,2,2},
{3,1,1,4,2,2,4,1,1,1,1,1,1,1},
};
for(int i =0; i <5;++i)
{
cout <<(unsigned int)array[i][0].a <<" ";
}
51gan
二七惨案cout << endl;
for(int i =0; i <5;++i)
{
cout <<(unsigned int)array[i][0].b[4]<<" ";
}
cout << endl;
for(int i =0; i <5;++i)
{
cout <<(unsigned int)array[i][0].c[1]<<" ";
}
cout << endl;
basic test[][5]=
{
{{1,0,0},
cri{2,0,0},
{3,0,0,0,1},
{2,2,1,2,2},
{3,1,1,4,2,2,4}}
唐溶};
for(int i =0; i <5;++i)
{
cout <<(unsigned int)test[0][i].a <<" ";
}
cout << endl;
for(int i =0; i <5;++i)
{
cout <<(unsigned int)test[0][i].b[3]<<" ";
}上海市第五十四中学
cout << endl;
system("pause");
return0;
}
结果为: