Mega Code Archive

 
Categories / C / Code Snippets
 

Simple union

union marks { float perc; char grade; } main () { union marks student1; student1.perc = 88.5; printf( "Marks are %f address is %16lu\n", student1.perc, &student1.perc); student1.grade = 'c'; printf("Grade is %c address is %16lu\n", student1.grade, &student1.grade); }