Data Structure Structure


A composite data type used to define a grouped list of variables, to be placed under one name in a block of memory is called structure. Thus, by using a single pointer to the structure, we can get access to different variables.


struct structure_name   
   data_type member1;  
   data_type member2;  
    data_type member;  

Structure Advantages:

  • Variables of different data types can be held by a structure.
  • Objects containing different types of attributes can be created.
  • The data layout can be reused across programs.
  • Other data structures like linked lists, stacks, queues, trees, graphs, etc., can also be implemented by a structure.

Structure Advantages Example :

void main( )  
struct employee  
int id;  
float salary;  
int phone;  
} ;  
struct employee e1,e2,e3,e4,e5;  
printf ("\nEnter id, salary & phone no. of 5 employees\n");  
scanf ("%d %f %d", &, &e1.salary, &;  
scanf ("%d %f %d", &, &e2.salary, &;  
scanf ("%d %f %d", &, &e3.salary, &; 
scanf ("%d %f %d", &, &e4.salary, &;  
scanf ("%d %f %d", &, &e5.salary, &;
printf ("\n Entered Data: ");  
printf ("\n%d %f %d",, e1.salary,;  
printf ("\n%d %f %d",, e2.salary,;  
printf ("\n%d %f %d",, e3.salary,;
printf ("\n%d %f %d",, e4.salary,;  
printf ("\n%d %f %d",, e5.salary,; 


Please follow and like us:
Content Protection by