c++之结构体二维数组对象的初始化

c++之结构体⼆维数组对象的初始化
前⾯我们说过,结构体的变量在内存中是顺序存储的,基于这⼀点就可以初始化结构体定义的⼆维数组对象,并检验这个事情。#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;
}
结果为:

本文发布于:2024-09-23 14:36:27,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/361256.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数组   结构   检验   对象   内存   蚕桑
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议