+ 1
union are collection of different datatype. They are used to group number of variables of different type in a single unit. for example #include<iostream.h> union Employee { int Id; char Name[25]; int Age; long Salary; }; void main() { Employee E; cout << "\nEnter Employee Id : "; cin >> E.Id; cout << "Employee Id : " << E.Id; cout << "\n\nEnter Employee Name : "; cin >> E.Name; cout << "Employee Name : " << E.Name; cout << "\n\nEnter Employee Age : "; cin >> E.Age; cout << "Employee Age : " << E.Age; cout << "\n\nEnter Employee Salary : "; cin >> E.Salary; cout << "Employee Salary : " << E.Salary; } Output : Enter Employee Id : 1 Employee Id : 1 Enter Employee Name : Kumar Employee Name : Kumar Enter Employee Age : 29 Employee Age : 29 Enter Employee Salary : 45000 Employee Salary : 45000
12th Oct 2017, 6:41 AM
felix jr lazarte
felix jr lazarte - avatar