Friday, October 2, 2020

Explain structure and union


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;
};


2 comments:

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...