当前位置:网站首页>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
边栏推荐
- clion安装教程
- realsense 选型大对比D455 D435i D415 T265 3D硬件对比
- 非参数化相机畸变模型简介
- C语言输入和输出(printf和scanf函数、putchar和getchar函数)
- 如何安装jsonpath包
- [UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
- [UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
- 友元函数,友元类,类模板
- ROS包nmea_navsat_driver读取GPS、北斗定位信息笔记
- 1006 finding a mex (hdu6756)
猜你喜欢
Class inheritance and derivation
基于VGG对五种类别图片的迁移学习
MySQL groups are sorted by a field, and the first value is taken
for()循环参数调用顺序
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
[ThreadX] h743 + ThreadX + Filex migration record
C#【文件操作篇】PDF文件和图片互相转换
如何安装jsonpath包
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
卷积神经网络实现CIFAR100数据集分类
随机推荐
C语言实用小技巧合集(持续更新)
【UDS统一诊断服务】三、应用层协议(1)
Eigen 库常用基本用法 备忘
sqlite3加密版
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
Static member
Friend function, friend class, class template
【UDS统一诊断服务】五、诊断应用示例:Flash Bootloader
C语言实现2048小游戏方向合并逻辑
C语言进阶要点笔记4
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
Vscode custom comments
Basemap库绘制地图
Robocode教程8——AdvancedRobot
[UDS] unified diagnostic service (UDS)
Make your own small program
逻辑回归原理及代码实现
C语言循环结构程序
PM2 deploy nuxt project
Detailed arrangement of knowledge points of University probability theory and mathematical statistics