1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 6 //定义一个结构体 7 //定义一个数据类型。固定内存大小的别名,还没有分配内存 8 /*struct Teacher 9 { 10 char name[5]; 11 int age; 12 };*/ 13 typedef struct Teacher 14 { 15 char name[64]; 16 int age; 17 int id; 18 }Teacher; 19 20 21 struct Student 22 { 23 char name[64]; 24 int age; 25 }s1,s2;//定义类型 同时定义变量 26 27 struct 28 { 29 char name[64]; 30 int age; 31 32 }s3, s4; //匿名类型 定义变量 33 34 //初始化变量的三种方法 35 //定义变量 然后初始化 36 // 37 Teacher t7 = { "aaaaa", 18, 01 }; //全局 38 struct Student2 39 { 40 char name[64]; 41 int age; 42 }s5 = { "names", 21 }; 43 44 struct 45 { 46 char name[64]; 47 int age; 48 49 }s6 = { "names", 30 }; 50 51 52 void copyTeacher01(Teacher *to,Teacher *from) 53 { 54 *to = *from; 55 } 56 int main() 57 { 58 Teacher t1 = { "aaaa", 32, 01 }; 59 Teacher t2; 60 t2 = t1; //=号操作下 编译器的行为 61 //C编译器提供简单的赋值操作 62 Teacher t3; 63 printf("t2.name:%s ",t2.name ); 64 printf("t2.age:%d ", t2.age); 65 copyTeacher01(&t3, &t1); 66 printf("t2.name:%s ", t3.name); 67 printf("t2.age:%d ", t3.age); 68 system("pause"); 69 return 0; 70 }