About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.

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