What is a structure at local scope in C language?

CServer Side ProgrammingProgramming

Structure is a collection of different datatype variables, grouped together under a single name.

General form of structure declaration

The structure declaration is as follows −

struct tagname{
   datatype member1;
   datatype member2;
   datatype member n;

Here, struct is the keyword.

tagname specifies name of structure.

member1, member2 specifies the data items that make up structure.


The following example shows the usage of the structure at a local scope.

struct book{
   int pages;
   char author [30];
   float price;


The following program shows the usage the structure at a local scope.

 Live Demo

   char name[20];
   int age;
   int salary;
   char add[30];
int manager(){
   struct{ //structure at local scope
   char name[20];
   int age;
   int salary;
   char add[50];
}manager ;
return manager.salary;
int main(){
   printf("enter the name of emp1:");
   printf("\nenter the add of emp1:");
   printf("\nenter the salary of emp1:");
   printf("\nenter the name of emp2:");
   // gets(emp2.name);
   printf("\nenter the add of emp2:");
   printf("\nenter the salary of emp2:");
   printf("\nemp1 salary is %d",emp1.salary);
   printf("\nemp2 salary is %d",emp2.salary);
   printf("\nmanager salary is %d",manager());
   return 0;


When the above program is executed, it produces the following result −

enter the name of emp1:Bob
enter the add of emp1:Hyderabad
enter the salary of emp1:500000
enter the name of emp2:Hari
enter the add of emp2:Chennai
enter the salary of emp2:450000
emp1 salary is 500000
emp2 salary is 450000
manager salary is 550000
Published on 12-Mar-2021 06:11:02