【C单链表】链表与尾插法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43560272/article/details/102619952

struct

struct的几种用法。
1、基本结构体定义

struct stu
{
	int score;
	int id;
	char name[20];
};

2、进阶结构体定义

struct stu
{
	int score;
	int id;
	char name[20];
}st1;

下面多了个st1,其实就相当于

struct stu
{
	int score;
	int id;
	char name[20];
};
struct stu st1;

这里还有其他结构体变量的定义,但都很少用,所以就不写了。推荐用第二种方法。

typedef

下面讲一下在第二种方法的基础上加上typedef会有什么变化

typedef struct stu
{
	int score;
	int id;
	char name[20];
}st;

我的理解是相当于把struct stu替换成了st,用的时候该声明还得声明,它并没有给你一个结构体类型变量,而是用的时候再去声明。
也即:实际作用和第一种相同,没有创建任何实质性东西,只是简化了声明。

这里我们创建链表用typedef的方法来创建。
(注意:给字符串添加变量用到的函数是strcpy(st1.name,“kejin”);不能直接赋值)

猜你喜欢

转载自blog.csdn.net/weixin_43560272/article/details/102619952