Home > Article > Backend Development > In C language, local scope refers to the visible scope of a variable, function, or other entity defined inside a specific block of code. Entities in local scope can only be accessed and used within the code block in which they are located, and cannot be accessed beyond this scope.
A structure is a collection of variables of different data types, grouped together by a single name.
The 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 Specify the structure name.
member1
strong>, member2 Specify the data items that make up the structure.The following example shows the usage of a structure in local scope.
struct book{ int pages; char author [30]; float price; };
The following program shows the usage of a structure within the local scope.
Real-time demonstration
#include<stdio.h> struct{ char name[20]; int age; int salary; char add[30]; }emp1,emp2; int manager(){ struct{ //structure at local scope char name[20]; int age; int salary; char add[50]; }manager ; manager.age=27; if(manager.age>30) manager.salary=650000; else manager.salary=550000; return manager.salary; } int main(){ printf("enter the name of emp1:"); //gets(emp1.name); scanf("%s",emp1.name); printf("</p><p>enter the add of emp1:"); scanf("%s",emp1.add); printf("</p><p>enter the salary of emp1:"); scanf("%d",&emp1.salary); printf("</p><p>enter the name of emp2:"); // gets(emp2.name); scanf("%s",emp2.name); printf("</p><p>enter the add of emp2:"); scanf("%s",emp2.add); printf("</p><p>enter the salary of emp2:"); scanf("%d",&emp2.salary); printf("</p><p>emp1 salary is %d",emp1.salary); printf("</p><p>emp2 salary is %d",emp2.salary); printf("</p><p>manager salary is %d",manager()); return 0; }
When the above program is executed, the following results will be produced -
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
The above is the detailed content of In C language, local scope refers to the visible scope of a variable, function, or other entity defined inside a specific block of code. Entities in local scope can only be accessed and used within the code block in which they are located, and cannot be accessed beyond this scope.. For more information, please follow other related articles on the PHP Chinese website!