What is the difference between Structure and Union? - ProProfs Discuss
Advertisement

What is the difference between Structure and Union?

Asked by S. Barnes, Last updated: Mar 05, 2024

+ Answer
Request
Question menu
Vote up Vote down

3 Answers

N. Reyes

N. Reyes

A good writer and orator as well.

N. Reyes
N. Reyes, Writer, B.ed, California

Answered Oct 22, 2019

These are both known to be container data types that are used to hold different types of data. One main difference is that structure will have the ability to hold separate locations for all of the data that will be placed while union will allow all of the members to be placed in just one location.

This means that if the memory location will be checked, the location will be different for all those that are saved in structure while those in the union will share the same memory location. The keywords that are used to activate these container data types are also different. You will use “struct” for structure and “union” for the union.

upvote downvote
Reply 

F. Ray

F. Ray

F. Ray
F. Ray, Student, Kansas City

Answered Sep 06, 2019

Structure and union are known to be user-defined types that are used in the C language. Some people feel that they are the same, but they still have some differences that would make one different over the other. Different keywords are used to define them. The "union" is used for the union while "struct" is used for the structure.

A union will share the space for all of the members while a structure will provide different memory areas for the various members of the group. There are different values that can be stored in a structure so that details will be easy to retrieve. For a union, there is only one value that can be stored.

upvote downvote
Reply 

M. Porter

M. Porter

Here to relax my mind a bit

M. Porter
M. Porter, Senior Executive, Master of Art, San Jose

Answered Aug 29, 2019

The structure contains variables of different data types. This allows for the combination of different data items. This is similar to the Union. However, in structure, each member has a separate space on the memory. The keyword “struct” is used to define a structure.

On the other hand, in Union, the keyword “union” is used to define a union. All members start from the same location in memory. The largest member determines the total memory space that is allocated. Other members of the Union share the same memory. A variable can only represent one member of the Union at a given time. This provides an efficient method of using the same storage for many functions.

upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.