结构体
来源:互联网 发布:nginx 设置项目根目录 编辑:程序博客网 时间:2024/05/18 15:52
1:什么是结构体
把一些复杂的数据组合在一起形成新的复合数据类型,叫做结构体。
2:为什么要有结构体?
为了表示一些复杂的事物,而普通的基本类型无法满足实际的应用需求。
3:结构体的基本格式
struct 结构名称 { 结构体参数列表; }比较好的应用方式就是将结构体变量定义在函数中,使程序更容易移植,耦合性更低。
4:怎么定义一个结构体和结构体的3种格式
/* 第一种方式:定义一个结构体*//* 这种方式应用更多*/struct comm { int heard; int lenth; int addmast; int addslav; int ctr; int end; int crc; }
/* 第二种方式:定义一个结构体*//* 定义结构体同时定义结构体变量*/struct comm { int heard; int lenth; int addmast; int addslav; int ctr; int end; int crc; }commucation;
/* 第二种方式:定义一个结构体*//* 定义结构体同时定义结构体变量,但是不定义结构体名称*/struct { int heard; int lenth; int addmast; int addslav; int ctr; int end; int crc; }commucation;
5:结构体程序范例
/*普通结构体定义,初始化,赋值*/# include<stdio.h>struct comm{ int heard; int add; int ctr; int crc;};int main(){ struct comm test;//结构体初始化 test.heard = 1;//结构体赋值 test.add = 2; test.ctr = 3; test.crc = 4; printf("%d,%d,%d,%d\n",test.heard,test.add,test.ctr, test.crc); return 0;}
/*普通结构体定义,初始化,赋值*/# include<stdio.h>struct comm{ int heard; int add; int ctr; int crc;};int main(){ struct comm test ;//定义结构体变量 struct comm * p = &test;//定义指向结构体变量的指针变量 p ->heard = 1;//结构体变量的赋值 p -> add = 2; p -> ctr = 3; p -> crc = 4; printf("%d,%d,%d,%d\n",p -> heard,p -> add, p -> ctr, p -> crc); return 0;}
0 0
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体,,,,
- 结构体
- 结构体
- Spring MVC 框架搭建及详解
- 查看Oracle执行计划的几种方法
- iOS生成二维码例子
- 全栈开发核心技术 Native Bridge原理与实现
- QDU 18 - 反转数字
- 结构体
- Shell 文件包含
- java常用的包和类
- Lua Save Table to File
- KERMIT,XMODEM,YMODEM,ZMODEM传输协议小结【转】
- calendar 类
- dreamweaver cs6
- C++组合问题的简单实现
- iOS读取二维码