Union in C

by Yogesh Khanna 28-Aug-18

0 747


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:


Discount Coupons



Comments

    Waiting for your comments

Leave a Reply