当前位置:网站首页>鹏哥C语言第七节课总结
鹏哥C语言第七节课总结
2022-07-26 10:36:00 【竹某】
一.结构体
结构体是C语言用于处理复杂对象的。结构体本质上是一种自定义类型。
#include <stdio.h>
#include <string.h>
enum Sex {
MALE,
FEMALE
};
struct Student {
char name[10];//成员
int age;
Sex sex;
};//定义结构体的语法,作用是提供了具有特定成员的新的数据类型
int main() {
//定义和初始化结构体变量的方法
Student Tom = {"Tom",19,MALE};//结构体是一种新的数据类型,可以用于定义复杂对象(变量)
printf("%s\t%d\n",Tom.name,Tom.age);//通过.来使用结构体变量的成员
Student* ptrTom = &Tom;//由于结构体是一种新的数据类型,自然也可以使用指针
ptrTom->age = 20;//通过结构体变量指针使用结构体变量的成员时,借助->
//ptrTom->name = "Sony"; C语言中的字符串不能如此赋值
strcpy(ptrTom->name,"Sony");
printf("%s\t%d\n", Tom.name, Tom.age);
}
区分三个概念:结构体,结构体变量,结构体变量指针。
结构体实质上是一种新定义的数据类型,用于处理复杂对象。(类似于Java中类的概念,只不过没有方法)
结构体变量实质上是我们需要处理的具体的复杂对象。(类似于Java中对象的概念,只不过没有方法)
结构体变量指针是指向结构体变量的指针。通过这个指针我们可以通过*解引用符来取得结构体变量,或是通过->来取得结构体变量的成员。总之和基本数据类型的指针使用类似,除了成员这方面外。
二.C语言的32个关键字
关键字 | 说明 |
---|---|
auto | 声明自动变量,与变量的生命周期相关 |
short | 声明短整型变量或函数,基本数据类型 |
int | 声明整型变量或函数,基本数据类型 |
long | 声明长整型变量或函数,基本数据类型 |
float | 声明浮点型变量或函数,基本数据类型 |
double | 声明双精度变量或函数,基本数据类型 |
char | 声明字符型变量或函数,基本数据类型 |
struct | 声明结构体变量或函数 |
union | 声明共用数据类型 |
enum | 声明枚举类型 |
typedef | 用以给数据类型取别名,注意和define区别,define不是关键字 |
const | 声明只读变量 |
unsigned | 声明无符号类型变量或函数 |
signed | 声明有符号类型变量或函数 |
extern | 声明变量是在其他文件正声明 |
register | 声明寄存器变量 |
static | 声明静态变量 |
volatile | 说明变量在程序执行中可被隐含地改变 |
void | 声明函数无返回值或无参数,声明无类型指针 |
if | 条件语句 |
else | 条件语句否定分支(与 if 连用) |
switch | 用于开关语句 |
case | 开关语句分支 |
for | 一种循环语句 |
do | 循环语句的循环体 |
while | 循环语句的循环条件 |
goto | 无条件跳转语句,不建议使用 |
continue | 结束当前循环,开始下一轮循环 |
break | 跳出当前循环 |
default | 开关语句中的“其他”分支 |
sizeof | 计算数据类型长度 |
return | 子程序返回语句(可以带参数,也可不带参数)循环条件 |
define不是关键字,请注意
三.其他的一些零散的知识点
边栏推荐
猜你喜欢
英语基础句型结构------起源
Tradingview 使用教程
[Halcon vision] image filtering
第7期:内卷和躺平,你怎么选
STM32 Alibaba cloud mqtt esp8266 at command
Comparison of packet capturing tools fiddler and Wireshark
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
[Halcon vision] programming logic
Application of.Net open source framework in industrial production
SAP ABAP 守护进程的实现方式
随机推荐
2022pta usual training questions (1-10 string processing questions)
工厂模式详解
Inheritance method of simplified constructor (II) - class inheritance in ES6
Analyze the hybrid construction objects in JS in detail (construction plus attributes, prototype plus methods)
英语基础句型结构------起源
C language callback function
.net operation redis sorted set ordered set
STM32 Alibaba cloud mqtt esp8266 at command
json_ object_ put: Assertion `jso->_ ref_ count > 0‘ failed. Aborted (core dumped)
MD5 encryption
.NET操作Redis List列表
移动端H5开发常用技巧总结
Zongzi battle - guess who can win
[C language] LINQ overview
Write to esp8266 burning brush firmware
Oracle cannot start tnslistener service cannot start
【dectectron2】跟着官方demo一起做
事务的传播性propagation
What if MySQL can't get in
algorithm