当前位置:网站首页>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统一诊断服务】一、诊断概述(2)— 主要诊断协议(K线和CAN)
- 代理服务器
- [UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
- gcc ,g++,gdb的安装
- selenium+PhantomJS破解滑动验证2
- 生成快捷方式
- Friend function, friend class, class template
- Protection of shared data
- 数组旋转
- GDB debugger installation and use
猜你喜欢

类的继承与派生
![[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture](/img/ef/173281ffb354b9abe1b730b89469cc.png)
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
[ThreadX] h743 + ThreadX + Filex migration record

Programmers can also write novels

大学概率论与数理统计知识点详细整理
逻辑回归原理及代码实现

拷贝构造函数

Graduation project, curriculum link, student achievement evaluation system

ArcGIS表转EXCEL超出上限转换失败
![[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)](/img/10/bd39bb03f5456a412650596208a391.png)
[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)
随机推荐
爬虫之requests基本用法
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
C#【文件操作篇】PDF文件和图片互相转换
Programmers can also write novels
【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
C语言实用小技巧合集(持续更新)
逻辑回归原理及代码实现
数组旋转
TensorFlow张量介绍
【UDS统一诊断服务】二、网络层协议(2)— 数据传输规则(单帧与多帧)
vs中能编译通过,但是会有红色下划线提示未定义标示符问题
Class inheritance and derivation
在visual stdio中运行qt程序
1006 finding a mex (hdu6756)
pyppeteer爬虫
Object array and object pointer
爬虫效率提升方法
【UDS统一诊断服务】三、应用层协议(2)
C语言进阶要点笔记4
爬取小米有品app商品数据