C复习 其他数据类型
#include <stdio.h> #include <stdlib.h> struct Student { int age; //4 float score; // 4/ long id; //4 char sex ; //2 vc 6.0 14 }; main() { struct Student st={80,55.6f,100010 ,'F'}; struct Student* pst; pst = &st; printf("age = %d\n",st.age); printf("score = %f\n",st.score); printf("id = %ld\n",st.id); printf("sex = %c\n",st.sex); // 结构体的长度 printf("长度 = %d\n",sizeof(st)); //printf("age = %d\n", (*pst).age); printf("age = %d\n", pst->age); system("pause"); // 调用windows下系统的命令 让程序暂停执行 方便观察程序的执行结果 }
#include <stdio.h> main( ) { struct date { int year, month, day; } today; // 联合体 是定义一块相同的内存空间 存放里面的数据 union { long i; int k; char ii; } mix; // 联合体的作用就是用来表示一组数据类型 数据的数据类型为这一组中的某一种数据类型 //注意 : 联合体里面的数据内容会相互覆盖 printf("date:%d\n",sizeof(struct date)); //12 printf("mix:%d\n",sizeof(mix)); mix.ii = 'A'; printf("k=%d\n",mix.k); system("pause"); }
#include <stdio.h> typedef int haha;//给数据类型起别名 enum WeekDay { Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday }; // c // int main(void) { haha i = 3; printf("%d\n",i); //int day; enum WeekDay day = Sunday; printf("%d\n",day); system("pause"); return 0; }