union共用体测试

This commit is contained in:
flykhan 2023-07-06 15:02:06 +08:00
parent 82b7331d9c
commit bc12f92223
1 changed files with 23 additions and 0 deletions

23
day4/union_test.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>
union Data{
int i;
float f;
char str[20];
};
int main(){
union Data data;
data.i = 10;
printf("data.i: %d\n", data.i);
data.f = 3.14;
printf("data.f: %f\n", data.f);
strcpy(data.str, "Hello");
printf("data.str: %s\n", data.str);
return 0;
}