C语言中的结构体是怎么定义的_怎么使用?

2023-06-15,,

结构体的定义

// 定义结构体st
struct st{
int a; // 成员a
int b; // 成员b
};
#include <stdio.h>
struct st{
int a;
int b;
};
int main()
{
struct st sst;
// 通过.来访问结构体中的值
sst.a = 10;
sst.b = 20; printf ("struct content is : %d, %d\n", sst.a, sst.b);
return 0;
}

输出结果

struct content is : 10, 20

枚举类型

enum em{
red_color = 0;
green_color,
black_color
};
#include <stdio.h>

// 定义枚举类型,没有定义默认从0开始,有值取值,无值默认上一个值加1
enum e_type{
red,
green,
blue
}; int main(int arc, char* argv[])
{
enum e_type et;
et = red;
printf ("the color is %d\n", et); et = blue;
printf ("the color is %d\n", et); return 0;
}

C语言中的结构体是怎么定义的_怎么使用?的相关教程结束。

《C语言中的结构体是怎么定义的_怎么使用?.doc》

下载本文的Word格式文档,以方便收藏与打印。