union共用体测试
This commit is contained in:
parent
82b7331d9c
commit
bc12f92223
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue