From bc12f92223e1ba9a69a6c4f40a75696677889c0a Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 6 Jul 2023 15:02:06 +0800 Subject: [PATCH] =?UTF-8?q?union=E5=85=B1=E7=94=A8=E4=BD=93=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day4/union_test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 day4/union_test.c diff --git a/day4/union_test.c b/day4/union_test.c new file mode 100644 index 0000000..90f13e0 --- /dev/null +++ b/day4/union_test.c @@ -0,0 +1,23 @@ +#include +#include + +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; +}