Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Union

Unions are declared in the same fashion as structs, but have a fundamental difference. Only one item within the union can be used at any time, because the memory allocated for each item inside the union is in a shared memory location.

Example1:-

				#include<stdio.h>
				#include<conio.h>
				union employee
				{
				  	int eno;
				  	float salary;
				};
				void main()
				{
				  	union employee x;
				  	clrscr();
				  	printf("Enter the Employee No.:");
				  	scanf("%d",&x.eno);
				  	printf("Employee No=%d\n",x.eno);
				  	printf("Enter the Salary:");
				  	scanf("%f",&x.salary);
				  	printf("Salary=%f",x.salary);
				  	getch();
				}
				

Computer Language >>
Introduction to C >>
Programming in C >>
Structure of C program >>
Variable in C >>


Home Clouds