C语言:结构体的定义与使用。

#include<stdio.h>

struct 结构体关键字;stu结构体标签;s1是创建的对象并初始化
//struct stu
//{
    
    
//	char name[20];
//	int age;
//	char sex[3];
//}s1 = { "李华",15,"男" }; 

typedef struct pi
{
    
    
	int x;
	int y;
};

//结构体声明,不占任何空间。
struct stu1
{
    
    
	char name[20];
	int age;
	char sex[3];
	struct pi p;
};


int main() {
    
    
	struct  stu1 s1= {
    
     "lihua",18,"男",{
    
    5,4} };
	
	printf("%d\n", s1.p.x);//5
	printf("%d\n", s1.p.y);//4


}

猜你喜欢

转载自blog.csdn.net/weixin_45275802/article/details/112588139