C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - General Questions (Q.No. 2)
2.
What is the similarity between a structure, union and enumeration?
Discussion:
50 comments Page 4 of 5.
Prem said:
1 decade ago
I think structure, union and enum - user defined data type.
Senthil.J said:
1 decade ago
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.
In short structures are used to share different memory locations for variable and union is used to allocate large memory for all variables.
Rohit8421 said:
1 decade ago
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.
Reshmi Singh said:
1 decade ago
Nice explanation raju. Enum is basically used for storing different datatypes variables. It is follow indexes like{0, 1, 2, . }.
Jithin james said:
1 decade ago
Can anyone explain more about Enum....plz
Vinaysan said:
1 decade ago
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.
Structures allocates diffrent memory locations.
Union allocates large memory.
Saravanan said:
1 decade ago
Nice Explanation raju.......
Raju Naidu said:
1 decade ago
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.
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.
Prabhu said:
1 decade ago
What is union ?
Sivaramakrishna said:
1 decade ago
But enum will store's integer constants only. How it can store all types of datatypes.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers