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:
49 comments Page 2 of 5.
Manmeet said:
9 years ago
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;
}b;
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;
This_month=feb;
struct book
{
int pages;
char name;
char author;
int edition;
}b;
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;
This_month=feb;
Urs Truely Naresh said:
9 years ago
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.
Enum has a set of value to choose from and it can be part of either the Struct/Union or stand-alone.
Hemant said:
10 years ago
Explain with program enum?
Pradeep kumar said:
1 decade ago
Use of structure we can use multiple data types in array.
We can define structure, union and enum.
STRUCTURE:
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
UNION:
It is same as structure but memory allocation is maximum of there data type. In union variable have share these memory.
ENUM:
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
a=0
b=1
c=2
d=4
But enum={a=6,b,c,d}
Here initialize the value of
a=6
b=7
c=8
d=9
We can define structure, union and enum.
STRUCTURE:
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
UNION:
It is same as structure but memory allocation is maximum of there data type. In union variable have share these memory.
ENUM:
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
a=0
b=1
c=2
d=4
But enum={a=6,b,c,d}
Here initialize the value of
a=6
b=7
c=8
d=9
Saravanakumar said:
1 decade ago
How to store multiple data types in array?
Alex said:
1 decade ago
Can any one give an example of enum that contains different type of data-types ?
Vivek said:
1 decade ago
Because these are user defined data type and each one contain own different data type collection.
Murty SVVSN said:
1 decade ago
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...
Ex. datatype array_name[size];
int array[5];
float a[10];
char a[5];
so on...
Mahesh said:
1 decade ago
Hi, what is an array?
Nups said:
1 decade ago
Please tell the proper difference between structure and enum and then union and enum?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers