Difference Between Array and Union in C

0
10
digitalample eye
Array
Union
Array is the collection of data items which will have the same name.
Union is a collection of a heterogeneous data types.
Each element has specific memory.
Each element has no specific memory space but space allocated for largest element is utilized by other sized element.
Keyword is not required to declare array.
Keyword is not required to declared union
Array has its type and these are.
One dimensional array and
multi-dimensional array
Union has not types.
The syntax of array:
One dimensional array;
Data type_array name[size of array]
It content only rows or columns.
Eg. Char name[20];
Multi-dimensional array;
Data type_array name[size1][size2];
Eg. Char name [5][25];
It contents rows or column both at a time.
Syntax of union:
Union user_defined_name{
Data type member 1;
Data type member 2;
.
.
};
Union user defined name
Variable 1, variable2
e.g struct student {
char name [20];
int age;
};
Union student one;

LEAVE A REPLY

Please enter your comment!
Please enter your name here