Guys tell me how can I write the following code In using Union instead of structure ?
#include <stdio.h> #include <stdlib.h> #include <string.h> union Student { char* name; int roll_number; float marks; }; int main() { int i = 0, n = 5; union Student student[n]; //Students data student[0].name = "Kapil"; student[0].roll_number = 1; student[0].marks = 73.6; student[1].name = "Vikas"; student[1].roll_number = 2; student[1].marks = 78.3; student[2].name = "Ajay"; student[2].roll_number = 3; student[2].marks = 87.4; // Print the Students information printf("Student Details:\n\n"); for (i = 0; i < n; i++) { printf("\tName = %s\n", student[i].name); printf("\tRoll Number = %d\n", student[i].roll_number); printf("\tTotal Marks = %f\n\n", student[i].marks); } return 0; }