C语言17

结构体对齐

#include<stdio.h>

struct AA
{
	char c;
	int a;
	short b;
	
};
struct BB
{
	int a;
	short b;
	double c;
	float d;
	char e;
	short f;
};
struct CC
{
	int a;
	char c[7];
};
int main()
{

	printf("%d\n",sizeof(struct AA));

	printf("%d\n",sizeof(struct BB));

	printf("%d\n", sizeof(struct CC));

	//以结构体成员最大的基本类型对齐
	//微观上也以最大的基本类型 对齐 ***基本类型***

	return 0;
}

链表

#include<stdio.h>

typedef struct Node
{
	int age;
	char* name;
	char* phone;
	struct Node* pNext;
}List;
int main()
{
	List a = { 5,"一饼","123",NULL};
	List b = { 5,"二饼","124",NULL };
	List c = { 5,"三饼","125",NULL };
	List d = { 5,"四饼","126",NULL };
	List e = { 5,"一万","127",NULL };
	List* p = &a;
	a.pNext = &b;
	b.pNext = &c;
	c.pNext = &d;
	d.pNext = &e;

	//遍历链表

	while (p != NULL)
	{
		printf("%d	%s	%s\n",p->age,p->name,p->phone);
		
		p = p->pNext;
	}



	return 0;
}

链表添加

#include<stdio.h>
#include<stdlib.h>

typedef struct Node
{
	int id;
	char* name;
	struct Node* pNext;

}List;

List* GetNode(int id,char* name)
{
	List* pTemp = (List*)malloc(sizeof(List));

	pTemp->id = id;
	pTemp->name = name;
	pTemp->pNext = NULL;

	return pTemp;
}


int main()
{
	List* p = GetNode(1, "peiqi");




	free(p);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值