共用内存,只能看到最后的分量。
#include <stdio.h>
#include <string.h>
union student
{
int id;
char name[20];
float percentage;
};
int main()
{
union student record;
record.id=1;
strcpy(record.name, "Raju");
record.percentage = 86.5;
// printf(" Id is: %d \n", record.id);
printf(" Name is: %s \n", record.name);
printf(" Percentage is: %f \n", record.percentage);
return 0;
}