About Me

Hey friends! My name is yuvraj basnet. I'm going to introduce myself.I have born and grown up in india(chandigarh) and I'm studying second year of B.C.A computer science field. My father serving in indian air force. My mother has been taking care of house hold. I am a friendly person, good thinker, I can work for longer hours without any break, only if I'm interested in that...My life style is very simple.

UNIONS IN C


What's up guys! My name is yuvraj basnet. In previous article I will explain you structures and its related concepts.
In this tutorial you will learn union in C Programming and its related concepts with examples. Union is similar to structure but slight different.
So, let's get started

                                UNION IN C
A union in C Programming is a user defined data type, which is to used to store different types of data similar to structure but with union you can only store the information in one field at any one time. 
 yeah know its little bit confusing but I will clear your doubts.

SYNTAX OF UNION DECLARATION:

Here, union is keyword to declare a union, name is a union name, x & y are the members of the union.

DEFINING A UNION IN C:

Here, union is defined with the name student and it has two members i.e, id of type int and name of char type with the size 20.

HOW TO ACCESS UNION MEMBERS:
1. Dot operator.
2. Arrow operator.

1.Dot operator: Dot operator is also known as member access operator in C programming.

SYNTAX :
union_variable.member_name; EXAMPLE: Salary.value = 1000; 2. Arrow operator: Arrow operator is used to access the member of structure and union. SYNTAX: union_pointer->member_name; EXAMPLE: Salary->value= 1000; BELOW TABLE RECALL YOU HOW TO DEFINE,DECLARE,ACCESS AND INITIALIZE UNION IN C



Post a Comment

0 Comments