Structure Vs Union

Structure

Union

struct keyword is used to define a structureunion keyword is used to define a union
In structure, each member get separate space in memoryTotal memory space allocated is equal to the member with the largest size
All other members use its own memory spaceAll other members share the same memory space
All the members can be initialized while declaring the variableThe only first member can be initialized while declaring the variable
An individual member can be accessed at a timeOnly one member can be accessed at a time
Syntax:
struct [structure name] {
member definition;
member definition;

};
Syntax:
union [union name] {
member definition;
member definition;

};
Example:
struct demo {
int integer;
float x;
}
Example:
union demo{
int integer;{
float x;{
}

By Arun

2 thought on “Structure Vs Union”

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.