Scope of Variable in C++

Prev Tutorial Next Tutorial

Scope of Variable in C++

In C++ language, a variable can be either of global or local scope.

Global variable

Global variables are defined outside of all the functions, generally on top of the program. The global variables will hold their value throughout the life-time of your program.

Local variable

A local variable is declared within the body of a function or a block. Local variable only use within the function or block where it is declare.

Example of Global and Local variable



int a;   // global variable
void main()
int b;    // local variable
a=10, b=20;
cout<<"Value of a: "<<a;
cout<<"Value of b: "<<b;


Value of a: 10
Value of b: 20

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain,, @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: WhatsApp no. 8882538826

Yahoo Advertisements