当前位置:网站首页>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统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
- Flask操作多个数据库
- Completely clean up MySQL win
- C#【文件操作篇】按行读取txt文本
- C语言输入和输出(printf和scanf函数、putchar和getchar函数)
- Static member
- [UDS unified diagnosis service] i. diagnosis overview (2) - main diagnosis protocols (K-line and can)
- 实现一个计算m~n(m<n)之间所有整数的和的简单函数
- Flask - 中间件
猜你喜欢
随机推荐
Arcpy为矢量数据添加字段与循环赋值
Round up a little detail of the round
在MFC中使用printf
Figure guessing game
【UDS统一诊断服务】一、诊断概述(3)— ISO 15765体系结构
Basemap库绘制地图
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
类和对象
Flask - 中间件
[UDS unified diagnostic service] III. application layer protocol (1)
C语言进阶要点笔记5
for()循环参数调用顺序
使用TransmittableThreadLocal实现参数跨线程传递
圆整 round 的一点点小细节
TensorFlow张量介绍
【UDS统一诊断服务】三、应用层协议(2)
C语言的运算符
C [document operation] PDF files and pictures are converted to each other
Matching between class template with default template argument and template parameter
搭建jpress个人博客









