STRUCTURE AND UNION
STRUCTURE :
- STRUCTURE is similar to array with a difference that it can store values of different datatypes.
- Structure is introduced for dealing with integer, character and float variable in a same name.
- Structure is a user defined data type.
- Structure is declared using keyword "struct".
-
SYNTAX :
struct struct_name { data_type variable_name; data_type variable_name; .... data_type variable_name; };//This semicolon is compulsory.
UNION :
- Union is similar to structure in that they also store different types of elements.
- Union is similar to Structure. Syntax of both are same but major difference between structure and union is 'memory storage'.
- In structures, each member has its own storage location, whereas allthe members of union use the same location.
- Union also contains manymembers of different types but Union can handle only one member at a time.
-
SYNTAX :
union union_name { data_type variable_name; data_type variable_name; .... data_type variable_name; };//This semicolon is compulsory.
Comments
Post a Comment