当前位置:网站首页>c语言结构体知识总结
c语言结构体知识总结
2022-08-03 13:10:00 【BSP初级小学僧】
C语言中,结构体是一种很常用的数据类型。简单而又复杂,能够用好它实属不易。下面总结下它的常见用法及容易出错的地方。
一、关于结构体的声明
1、匿名声明。例如:
struct {
int i,j;
}point;说明:
这段代码的含义是,声明一个无名(anonymous)的结构体,并创建了一个结构体变量point。如果这段声明是放在全局域内,那么point内的变量将被初始化为默认值,换句话说,以这种方式声明结构体变量时就已经为它分配了内存空间。
适用于该结构体只需要产生一个变量!本例中,该匿名结构体将有且仅有point这个结构体变量!
2、结构体的常规声明
struct stu_info//结构体类型定义
{
int id;
char name[20];
char add[20];
int age;
};注意花括号后面的分号;
二、结构体的初始化
1、局部变量初始化
struct stu_info stu01={
.tel=1768393435,
strcpy(stu01.sex,"男"),
strcpy(stu01.mingzi,"夏洛特007")
}; 2、常规初始化
struct stu_info
{
char mingzi[20];//名字
long long tel; //手机号
char dress[20];//地址
long long QQ;//qq号
char sex[10];//性别
struct birth bir;//结构体的嵌套!!!!!
}stu03={"夏洛特2号",10086,"北京",10010,"女"};//初始化 3、常规赋值
struct stu_info stu01;
strcpy(stu01.mingzi,"夏洛特");
strcpy(stu01.dress,"西安");
stu01.QQ=1008611;
strcpy(stu01.sex,"男");
stu01.tel=1768393435; 边栏推荐
- Relia Tech活性VEGFR重组蛋白丨小鼠 VEGF120实例展示
- 类和对象(中上)
- In order to counteract the drop in sales and explore the low-end market, Weilai's new brand products are priced as low as 100,000?
- 国产替代风潮下,电子元器件B2B商城系统如何助力企业突围市场竞争
- An动画优化之传统引导层动画
- An动画优化之补间形状与传统补间的优化
- leetcode/字符串中的所有变位词(s1字符串的某个排列是s2的子串)的左索引
- 【二叉树】统计最高分的节点数目
- The components of the basis of An animation movie clip animation between traditional filling
- d作者:d的新特性
猜你喜欢

An动画基础之元件的图形动画与按钮动画

如何合理安排一天,做到高效备考?
![[微服务]多级缓存](/img/58/72e01c789a862c058cba58b9113272.png)
[微服务]多级缓存

MySQL数据表操作实战

An animation optimization of shape tween and optimization of traditional tweening

软件测试面试(四)
![[Blue Bridge Cup Trial Question 48] Scratch Dance Machine Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation](/img/4c/b41d64c13d6903aa38cc46dea44519.png)
[Blue Bridge Cup Trial Question 48] Scratch Dance Machine Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation

Hanyuan Hi-Tech G8032 standard ERPS ring network switch Gigabit 4 optical 10 electrical industrial Ethernet switch ring network + WEB management + SNMP VLAN planning

scala安装包

In order to counteract the drop in sales and explore the low-end market, Weilai's new brand products are priced as low as 100,000?
随机推荐
Sogou news - dataset
An动画基础之按钮动画与基础代码相结合
背后的力量 | 提升医疗服务“速度“和“温度” 华云数据助力上海国际医学中心加速智慧医院建设
leetcode 448. Find All Numbers Disappeared in an Array 找到所有数组中消失的数字(简单)
使用百度EasyDL实现施工人员安全装备检测
Notepad++ 安装jsonview插件
An introduction to basic tools for selecting line tools (package church)
超大规模的产业实用语义分割数据集PSSL与预训练模型开源啦!
The components of the basis of An animation movie clip animation between traditional filling
An animation optimization of traditional guide layer animation
Golang structs & methods
力扣刷题 每日两题(一)
VLAN 实验
如何让history历史记录前带时间戳
Golang sync.WaitGroup
An工具介绍之摄像头
leetcode 11. 盛最多水的容器
“芯片法案”通过后,美光承诺在美国扩产
类和对象(中下)
ECCV 2022 | AirDet: 无需微调的小样本目标检测方法