Difference between Structure and Union

Jan 20 • Resources • 2203 Views • 4 Comments on Difference between Structure and Union

Difference between Structure and Union

The post allows you find the basic knowledge as well as interview questionnaire on Structure, Union and the difference between the both.

 

Question 1. What is Structure in C++?

Answer. A Structure is a collection of variable referenced under one name. we can also say that structure is a user defined data type. sometimes, some logically related elements need to be treated under one unit. For instance, the element storing a student’s information ( e.g., roll no., name, class, marks, grade) need to be processed together under one roof. Similarly keeping a date’s information (e.g., day, month, and year) need to be processed together. To handle and serve to such situations, C++ offers structures.

Question 2.

Question . Difference between Structure and Union?

Answer. Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. In union,one block is used by all the member of the union but in case of structure, each member have their own memory space.
Union allocates the memory equal to the maximum memory requried by the member of the union but structure allocates the memory equal to sum of the memory allocated to its each individual members.
In Union, one block is used by all the member of union but in case of structure, each member have their own memory space.
Union allocates the memory equal to the maximum memory requried by the member of the union but structure allocates the memory equal to total memory requried by the members. In Union, one block is used by all the member of union but in case of structure, each member have their own memory space.

Basic Questionaire on Sturcture , Union and the difference B/w both???

 

 

 

 

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published. Required fields are marked *

4 Responses to Difference between Structure and Union

  1. sanjana kumari says:

    We are very well aware of how ordinary variables can hold one piece of information and how arrays can hold can hold a number of pieces of information of same data type. These two data types can handle a great variety of situations. But quite often we deal with entities that are collection of dissimilar data types. So to overcome this situation we need to use Structure and Unions. Both deal with the collection of dissimilar data types. The major difference between the two has been properly explained in this article and I would suggest all to read it. It is really helpful.

  2. Er Ketan Joshi says:

    This is what we called a basic knowledge about C++. It is really necessary to know the basic of any programming language . This post will really helpful to those student who is fresher in computer stream and they want to know what exactly is C++ language and it is very important to know the basics. And one more think “if our base is solid then building never fall down” so always take care of your base that is your basic knowledge about any subject.

  3. Singh Saurabh says:

    Important and Infrmative article Regarding Computer Science Branch..Check this

  4. Pallavi sinha says:

    If u wan some important question on union and structure chk this valuable article …….this will help u alot

« »