Simple union : Union « Data Type « C / ANSI-C






Simple union

union marks {
  float perc; 
  char grade; 
}

main () {
  union marks student1;
  
  student1.perc = 98.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);
}


           
       








Related examples in the same category

1.The operation of a union