#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
struct B//定义一种新的数据类型struct B
{
char a[20];
int b;
};
struct student
{
struct B b;//结构体中可以套结构体
char name[20];//要写字符数串大小
int age;
}s1={{"acd",13},"aed",19};//要加分号
//定义结构体的同时创建全局变量s1
//s1是结构体变量
void print1(struct student a)
{
printf("%s ", a.b.a);
}
void print2(struct student* a)
{
printf("%s ", a->b.a);
}
int main()
{
struct student s2 = { {"asd",23},"zya",18 };//初始化s2
//s2的数据类型是struct student
//{ }里面的{ }可以去掉
printf("%s ", s2.b.a);
printf("%d ", s2.age);
struct student* s_p = &s2;
printf("%s ", ( * s_p).b.a);// *s_p必须要加( )
printf("%s ", s_p -> b.a);
print1(s2);
print2(&s2);//建议使用传址调用 -> 节省空间,可改变内容
return 0;
}
//栈是一种数据结构,先进的后出,后进的先出