Structure :
▪️ Structure is the collection of non homogeneous data elements.
▪️ Each data element has it's own storage area in memory.
▪️ The size allocated to store the structure, in the memory, is the sum of memory required to store all the elements.
▪️ All elements can be access any time.
▪️ "struct" keyword is used to defin and declared structure format and it's variable.
▪️ Variable declare within struct is called as structure member and name of the structure is called as structure tag.
▪️ Structure member can not be initialized within the structure defination.
▪️ All elements of structure variable can be initialized at the time of declaration.
▪️ Defination of structure
struct student
{
char name[10];
int roll_no;
float per;
};
Union :
▪️ Union is also the collection of non homogeneous data elements.
▪️ All the data elements share the same memory location.
▪️ Size required to store union is the same as tge size required to store the element of the largest variable type in union.
▪️ One element can be accessed at a time.
▪️ "union" key word is used to defineand declared union format and it's variable.
▪️ Variable declated within union is known as union member and namecof union is called as union tag .
▪️ Union member can not be initialized within the union defination .
▪️ only first element of union variable can be initialized at the time of declaration.
▪️ Definition of union
union student
{
char name[10];
int roll_no;
float per;
};
Good
ReplyDeleteNice!
ReplyDelete