What do you mean by “local” “global” and “static” variables? Explain with examples.

Local variable : any variable which is declared within the function is called local variable. This type of variable can be accessed within the same number function only.

Global Variable : any variable which is declared before main function is called global variable. This variable can be accessed from any member functions.

Static Variable : any variable which is declared by using keyword static is called static variable. The value of static variable is remain fixed for the other function but may change within same function boundary.

Program use of local, global and static variables

#include<stdio.h>
#include<conio.h>
int a=8;b=10; //global variable
void display();
void main(){
int x=9; //local variable
static int z=7; //Static variable
printf("the local variable x=%d and global variable a=%d",x,a);
printf("the value of static variable in main function=%d",z);
getch();
}
void display(){
printf("the value of a=%d, and b=%d",a,b");
}
image_pdfOpen as Pdfimage_printPrint

About the author

ProPathshala

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *