Explain union, C/C++ Programming

Assignment Help:

Unions

A union is also like a structure, except that only single variable in the union is stored in the allocated memory at a time. It is a collection of mutually exclusive variables, which means all of its member variables share the similar physical storage and only one variable is explained at a time. The size of the union is equal to the largest member variables. A union is defined as follows :

                union tag

                 {

                                type memvar1;

                                type memvar2;

                                type memvar3;

                                :

                                :

                 };

 

A union variable of this data type can be declared as follows,

Union tag variable_name;

e.g.

                union utag

                 {

                                int num;

                                char ch;

                 };

                union tag filed;

The above union will have two bytes of storage allocated to it. The variable num can be accessed as field.sum and ch is accessed as field.ch. At any time, only one of these two variables,  can be referred to. Any change made to single variable affects another.

 


Related Discussions:- Explain union

basic salary of employees & calculate net salary, basic salary of employee...

basic salary of employees & calculate net salary in C++ Programming

Program, salotion of programes

salotion of programes

Explain external variables, External Variables Different functions of t...

External Variables Different functions of the similar program can be written in different source files and can be compiled together. The scope of a global variable is not limit

GPA Calculator, I am having trouble declaring a variable and returning a va...

I am having trouble declaring a variable and returning a value from my function.

ARRAY, A PROGRAM TO CALCULATE AREA OF TRIANGLE

A PROGRAM TO CALCULATE AREA OF TRIANGLE

Operations on strings, 1 Aims The main purpose of the assignment is to ...

1 Aims The main purpose of the assignment is to let you practice the following programming techniques: perform operations on pointers to basic and more complex types;

Assigment Help, I need help in the C++ programming assignment. I can send t...

I need help in the C++ programming assignment. I can send the files the assignment is times 3hrs.

Writing a c++ program, how can I write a c++ program that generate all evn ...

how can I write a c++ program that generate all evn numbers less than 1000?

Name the operators which cannot be overloaded?, Q: Name the operators which...

Q: Name the operators which cannot be overloaded? A:sizeof, ., .*, .->, ::, ?:

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd