C Programming - Structures, Unions, Enums - Discussion


What is the similarity between a structure, union and enumeration?

[A]. All of them let you define new values
[B]. All of them let you define new data types
[C]. All of them let you define new pointers
[D]. All of them let you define new structures

Answer: Option B


No answer description available for this question.

Runa said: (Jul 27, 2010)  
Structures unions and enumeration is used to create a new datatyppe that holds all kinds of datatype that is it includesn a datatype that can hold int, float, char, array inside a user ndefined datatype.

Pradeep Bhupathi said: (Aug 25, 2010)  
Array, pointer, structure, union, enum - These all are user defind data types in c language.

Lokeswari said: (Dec 5, 2010)  
What is pointer?

Yamuna said: (Dec 9, 2010)  
Since Structure,Union,Enum are all User defined data types so user can use new values...thus logic is simple.. :-)

Varun said: (Jan 7, 2011)  
But what is the difference?

Lipsa said: (Feb 1, 2011)  
I agree with the runa and the main difference is the structure allocate different memory location with the data types but union allocate one large memory location for their members.

Surya said: (Mar 10, 2011)  
These are used to create a new data type that holds all data types.

Nagarjun said: (Mar 10, 2011)  
S.I agree vtt the Lips .but Enumrated gives the different states of a variable
Enum person
where the person having 2 states male r female;

Devi said: (Mar 11, 2011)  
Thanks for your explanation.

Ashish Moreshwar said: (Apr 12, 2011)  
Question is the similarity between a structure, union and enumeration. I think These all are the user defined data type. That holds various types of other data types.

Sivaramakrishna said: (Sep 23, 2011)  
But enum will store's integer constants only. How it can store all types of datatypes.

Prabhu said: (Sep 24, 2011)  
What is union ?

Raju Naidu said: (Oct 28, 2011)  
Structure,union,enum all are userdefined datatypes.

Let we take one senario for structure.

Suppose in my programm i've to take the 100 variables. If you want to define many variables of different datatype, instead of declaring all those variables individually just go through sructure.Just define the one structure and take all those variables into that structure.

Then if you want to access any variable, just take the structname and dot operator and variable name.then we can access those variables.

union also used for storing the different datatypes variables. But there is small difference between structure and union.i.e
In structures we can acess all those variables at a time because of they are sharing different memory locations.

But in unions whatever we declare in the union those all are sharing same memory that's why at a time we can access only one variable. enum also used for storing user defined variable

Ex: enum { married,divorced,unmarred}

By defaultley married is indexed by o,divorced is 1, unmarried is 2.

If you want to change this order you can change by using married=10 then divorced = 11, unmarried = 12.

Saravanan said: (Dec 4, 2011)  
Nice Explanation raju.......

Vinaysan said: (Dec 8, 2011)  
I agree with runs. He/she said very nice defnition. And one more is the main difference between structure and union is

Structures allocates diffrent memory locations.

Union allocates large memory.

Jithin James said: (Dec 19, 2011)  
Can anyone explain more about Enum....plz

Reshmi Singh said: (Dec 22, 2011)  
Nice explanation raju. Enum is basically used for storing different datatypes variables. It is follow indexes like{0, 1, 2, . }.

Rohit8421 said: (Jan 13, 2012)  
I'm agree that structures and union are use to define new data type , but how enumeration is use to define new data type. it just internally store an integer value.

Senthil.J said: (Aug 10, 2012)  
I agree with raju he have given a good explanation about these.

In short structures are used to share different memory locations for variable and union is used to allocate large memory for all variables.

Prem said: (Sep 2, 2012)  
I think structure, union and enum - user defined data type.

Ravendra Patel said: (Sep 5, 2012)  
The working of structure and union is the same but the difference is in their memory allocation. The size of an structure is the summation of his all the member's size while the size of a union is the same as his largest member's size.

Anu said: (Sep 8, 2012)  
Difference between structure and union is that......

structure allocates individual memory to all the variables declared in the structure based on there data types


unions allocation the memory takes place based on the variable which occupies largest memory space based on there data type

for example

if in a union 2 variables with data types char and int are given then it allocates a memory of 4 byte in GCC since it occupies more space than char the same memory is shared for both of them

Priya said: (Sep 26, 2012)  
Can any one explain differnce between struct and enum ?

Swapnil said: (Oct 6, 2012)  
@Priya: In structure only collection of different type of variables which are binded in one unit but enum are they who allows us to assign a particular value from given set to variable.

enum days {MON=-1, TUE, WED, THU, FRI, SAT};

//This allows days to have val from MON,TUE, WED,THU,FRI,SAT
Whose vaule are from -1 to 4. As MON=-1,TUE=0.

Nithya said: (Dec 13, 2012)  
These are the user defined data types. But enumeration only allocate in integer data types. Then how does is allocated for new data types for others?

Knp said: (Jan 29, 2013)  
In short structures are used to share different memory locations for variable and union is used to allocate large memory for all variables.

Kamal said: (Mar 18, 2013)  
What is linked list in programming on C?

Pooja said: (Mar 25, 2013)  
Are structure & union just differ in tums of memory. Is there not any other difference.

Rj Kumar said: (Aug 20, 2013)  
Because these are user defined data type that use to define another data type.

Nups said: (Oct 3, 2013)  
Please tell the proper difference between structure and enum and then union and enum?

Mahesh said: (Oct 5, 2013)  
Hi, what is an array?

Murty Svvsn said: (Oct 22, 2013)  
An array holds a collection related data items that are all belongs to one particular data type, i.e a single name to all data items but the data items have different memory locations.

Ex. datatype array_name[size];
int array[5];
float a[10];
char a[5];

so on...

Vivek said: (Oct 26, 2013)  
Because these are user defined data type and each one contain own different data type collection.

Alex said: (Jan 27, 2014)  
Can any one give an example of enum that contains different type of data-types ?

Saravanakumar said: (Jul 12, 2014)  
How to store multiple data types in array?

Pradeep Kumar said: (Jul 13, 2014)  
Use of structure we can use multiple data types in array.
We can define structure, union and enum.

It is a user define data type that have we use define variable of different type of data type. it have allocate individual memory to all the variables declared in the structure based on there data types

It is same as structure but memory allocation is maximum of there data type. In union variable have share these memory.

It have have declared different data type. the value of data type start with 0 by default.

Ex. enum={a,b,c,d};
Here initialize the value of

But enum={a=6,b,c,d}
Here initialize the value of

Hemant said: (Mar 27, 2015)  
Explain with program enum?

Urs Truely Naresh said: (Jun 10, 2015)  
Structure occupies fixed width of memory space, while Union takes the required memory based on the values.

Enum has a set of value to choose from and it can be part of either the Struct/Union or stand-alone.

Manmeet said: (Jun 19, 2015)  
Structures: Structure is denied as a collection of similar elements with different data types. The syntax of structure is :

struct book
int pages;
char name;
char author;
int edition;
Unions: It is a special data type which looks like a structure but are different from each other .
The syntax of union is :
union book
char name;
int pages;
int edition;
union book b;

The major difference between is there sizes.

In structures all the sizes of attributes are considered where as in case of unions only data type with max size is considered.

Enum: These are the special variables which can assume values which have been previously defined.

Syntax is:

enum month{jan=1, feb, march, april, may}.

enum month this_month;


Jiten said: (Jul 5, 2015)  
Structure are user define data types in which you can store more than one data type variable. It is similar to union. But in union you can access only one value at a time because in union memory allocated to only one member at a time. While in structure all of its member have its own memory. That's why structure is taking more memory then union.

Lokija said: (Sep 7, 2015)  
I can't understand explain clearly.

Sarath said: (Oct 9, 2015)  
Because the secondary data types are arrays, pointers, structures, union and enum, they are user defined data types All of them let you define new data types.

Pallavi said: (Jan 9, 2016)  
Structure mean collection of multiple element that can be of different data types. Definition of union is same of structure but only data element is stored in union variable.

Sonali Adhav said: (Feb 25, 2016)  

Are the user defined or secondary types of data type in C?

Neelima said: (May 25, 2016)  
Do the outputs for structure & union is same?

Vishu said: (Dec 16, 2016)  

Linked list: list is a collection of elements. There are 2 ways of maintaining list in computer memory. The first way is to take an array for sorting elements of the list. But arrays have some disadvantage. Insertion and deletion of the element require more processing. The second way is implementing a list in a memory by using a self-referential structure.

Rekha said: (Jun 27, 2017)  
Which is better to use structure or union? Any one explain in detail.

Bhushan Shriram said: (Feb 10, 2018)  
Please, explain about union?

Keerthana said: (Jul 31, 2018)  
All are user-defined datatypes which allow the user to create their own datatype which can be a combination of int, float, char, etc.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.