#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//结构体
//声明:值的集合,值被成为成员变量,可以是不同类型的变量。
//描述一个学生-一些数据
//名字、年龄、电话、性别
//struct结构体关键字,stu结构体标签,struct stu结构体类型
typedef struct stu
{
//成员变量
char name[20];
short age;
char tele[12];
char sex[5];
}stu;
int main()
{
stu s1 = {"小黄",20,"16888224567","男"};
struct stu s2 = {"小红",21,"16243823467","女"};
return 0;
}
struct S
{
char a;
int b;
char arr[20];
double c;
};
struct T
{
char ch[10];
struct S s;
char* p;
};
int main()
{
char arr[] = "hello world";
struct T t = { "xixi",{'r',520,"hello wzry",3.14},arr};
printf("%s\n", t.ch);
printf("%s\n", t.s.arr);
printf("%d\n", t.s.b);
printf("%s\n", t.s.arr);
printf("%lf\n", t.s.c);
printf("%s\n", t.p);
return 0;
}
typedef struct stu
{
//成员变量
char name[20];
short age;
char tele[12];
char sex[5];
}stu;
void printf1(stu s)
{
printf("name: %s\n", s.name);
printf("age: %d\n", s.age);
printf("tele: %s\n", s.tele);
printf("sex: %s\n", s.sex);
}
void printf2(stu* ps)
{
printf("name: %s\n", ps->name);
printf("age: %d\n", ps->age);
printf("tele: %s\n", ps->tele);
printf("sex: %s\n", ps->sex);
}
int main()
{
stu xs = { "旺财",23,"16822738809","男" };
printf1(xs);
printf2(&xs);
return 0;
}
//数据结构
//----线性数据结构
//顺序表
//链表
//栈:先进后出,后进先出。函数数据传参是属于压栈操作(函数栈帧的创建和销毁)
//---------
标签:struct,sex,char,stu,tele,printf,结构 From: https://blog.51cto.com/u_16189143/6919881