
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What is a structure at local scope in C language?
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.
Example
The following example shows the usage of the structure at a local scope.
struct book{ int pages; char author [30]; float price; };
Example
The following program shows the usage the structure at a local scope.
#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("
enter the add of emp1:"); scanf("%s",emp1.add); printf("
enter the salary of emp1:"); scanf("%d",&emp1.salary); printf("
enter the name of emp2:"); // gets(emp2.name); scanf("%s",emp2.name); printf("
enter the add of emp2:"); scanf("%s",emp2.add); printf("
enter the salary of emp2:"); scanf("%d",&emp2.salary); printf("
emp1 salary is %d",emp1.salary); printf("
emp2 salary is %d",emp2.salary); printf("
manager salary is %d",manager()); return 0; }
Output
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
- Related Articles
- Write a structure in local scope program using C language
- What are the local and global scope rules in C language?
- What is the scope of local variables in Java?
- What is union of structure in C language?
- What are Local Scope Variables in Postman?
- Explain scope of a variable in C language.
- What are the local static variables in C language?
- Structure declaration in C language
- Can a local variable's memory be accessed outside its scope in C/C++?
- Declaring a structure with no members in C language
- Explain scope rules related to the functions in C language
- What is a structure in C#?
- Explain linear data structure queue in C language
- What is the scope resolution operator in C#?
- Explain the scope rules related to the statement blocks in C language

Advertisements