Union in C
0 3359
The syntax of Union in C programming language is identical to structure except for the keyword.
Syntax of Union in C Programming Language:
Union Tag-name
<Datatype1> m1
<Datatype2> m2
.
.
.
}union-var;
Simple example explaining union in C programming language
Union Student
{
Int rollnumber;
Char name[15];
};
main()
Union student stud;
Printf("enter student roll number");
Scanf("%d",&stud.rollnumber);
Printf("enter student name");
Scanf(%s,&stud.name);
Printf("detail of student");
Printf("rollnumber:%d"stud.rollnumber);
Printf("student name:%s"stud.name);
getch();
}
Share:
Comments
Waiting for your comments