In the C programming language, a union is a user-defined datatype. It is a memory region that contains a collection of variables of various datatypes. We can define a union with numerous members, but only one member can contain a value at any given time. Memory is saved by using C unions.
All members of a union have access to the same memory location. In the C programme below, for example, both x and y have the same position. We can see how changes in x are mirrored in y when we adjust x. #include stdio.h>/ Structures and declarations of union are the same thing.
The most typical purpose of a union is to allow various data types to access a single location, such as hardware input/output access, bitfield and word sharing, or type punning. Low-level polymorphism can also be found in unions.
When we define the union, we discover that it is defined in the same way that the structure is defined, with the exception that the union data type is specified using the union keyword, whereas the structure is defined using the struct keyword.
When we define a union, the memory allocated for a union variable of the type is the same as the memory required for the union's largest member, and other members share this memory space. "char arr[8]" is the largest member in the example above. As a result, the size of the union test is 8 bytes.
Learner's Ratings
4.4
Overall Rating
69%
18%
5%
4%
4%
Reviews
H
H Naga Priya Bai
4
best and useful to keep learning and practice the c-language. Explained well sir. thank you
R
Rakshitha Resham
5
Goid
S
syed qutub ghoush
5
good, but there are still some loop holes ,
H
Harshad Futane
5
i am studying 7 th standard in semi english school of pimpri
i am founding the best free classes of programing
and i found it the name of class is *LEARNVERN*
and the class is best.
THANK YOU
A
Avinash Kumar
4
The Course is Amazing and content is also amazing bu i want the notes please provide that sir ..
I
Ishant kumar
4
best
K
Krishna dhangar
5
nice,teaching
A
Ashutosh Thakkar
5
It is as same as any college can offer or if you refer any book this as same as that. Great teaching of C language. I am really happy about this course
I
Ishant Kumar
5
i love c language
P
PATAN MASTHAN
5
sir need c notes it is very useful us to read after listening class so i request u do please provide notes......................masthimasthan786@gmail.com this is my mail
Share a personalized message with your friends.