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.
Yamuna said:
1 decade ago
Since Structure,Union,Enum are all User defined data types so user can use new values...thus logic is simple.. :-)
Varun said:
1 decade ago
But what is the difference?
Lipsa said:
1 decade ago
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:
1 decade ago
These are used to create a new data type that holds all data types.
Devi said:
1 decade ago
Thanks for your explanation.
Ashish Moreshwar said:
1 decade ago
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:
1 decade ago
But enum will store's integer constants only. How it can store all types of datatypes.
Prabhu said:
1 decade ago
What is union ?
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.
Kamal said:
1 decade ago
What is linked list in programming on C?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers