c
#include <stdio.h>
typedef struct
{
char *leader;
char *capital;
} Nation;
typedef struct
{
char *plan_name;
float time_left;
} Plan;
typedef struct
{
Plan five_plan;
Nation republic;
} Union;
int
main (void)
{
Union soviet;
soviet.five_plan.time_left = 4.7f;
soviet.five_plan.plan_name = "The great steelovertake";
soviet.republic.leader = "General Secretary";
soviet.republic.capital = "Moscow";
printf ("Remaining: %.1f years\n", soviet.five_plan.time_left);
printf ("What: %s\n", soviet.five_plan.plan_name);
printf ("Leader: %s\n", soviet.republic.leader);
printf ("Capital: %s\n", soviet.republic.capital);
return 0;
}Here i use a struct named Union as union memory get overwritten, but then, why use unions instead of structs?
I cant see many cases where union would be better than just a struct.
That was all.
Bye!