当前位置:网站首页>C语言结构体指定初始化
C语言结构体指定初始化
2022-04-23 05:50:00 【tilblackout】
很多时候我们并不会使用到结构体中每一个成员,只想初始化其中某几个成员,这时候可以使用结构体的指定初始化。
struct student {
char *name;
int num;
int age;
char group;
float score;
} ;
(1)常规情况下:所有变量都要初始化
struct student stu1 ={"Tom",12,18,"A",136.5};
(2)指定初始化:在变量名前加一个“.”,每行用逗号隔开
struct student stu1={
.score=136.5,
.age=18,
.group="A",
} ;
例:
struct test{
int a;
char b;
};
struct test c[] = {//创建三个成员,部分初始化
[0] = {
.a = 1,
},
[2] = {
.b = 'a',
},
};
版权声明
本文为[tilblackout]所创,转载请带上原文链接,感谢
https://blog.csdn.net/tilblackout/article/details/123419304
边栏推荐
猜你喜欢
随机推荐
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
Quaternion multiplication
vs中能编译通过,但是会有红色下划线提示未定义标示符问题
Opencv uses genericindex for KNN search
相机标定:关键点法 vs 直接法
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
Initialization of classes and objects (constructors and destructors)
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
clion安装教程
Wechat applet request encapsulation
[stepping on the pit] MELD in win11 wsl2 cannot be used normally. Problem repair
Protection of shared data
Camera calibration: key point method vs direct method
sqlite编译
【UDS统一诊断服务】二、网络层协议(2)— 数据传输规则(单帧与多帧)
圆整 round 的一点点小细节
LaTeX配置与使用
jenkspy包安装
For() loop parameter call order