91学习

陪伴你每一天!

用共用体设计一个一次只能装一种水果的罐头瓶

#include <stdio.h>

#include <string.h>


struct peaches{

char name[64];

};

struct coconut{

char name[64];

};

struct hawthorn{

char name[64];

};

union tin{

struct peaches p;

struct coconut c;

struct hawthorn h;

};

int main(){

union tin t;

strcpy(t.p.name,"桃");

strcpy(t.c.name,"椰子");

strcpy(t.h.name,"山楂");

printf("这个罐头瓶装%s\n",t.p.name);

return 0;

}

加威信18790284560免费送POS机.jpg

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。