0 votes
in C Plus Plus by
Comment on Local and Global scope of a variable.

1 Answer

0 votes
by
The scope of a variable is defined as the extent of the program code within which the variable remains active i.e. it can be declared, defined or worked with.

There are two types of scope in C++:

Local Scope: A variable is said to have a local scope or is local when it is declared inside a code block. The variable remains active only inside the block and is not accessible outside the code block.

Global Scope: A variable has a global scope when it is accessible throughout the program. A global variable is declared on top of the program before all the function definitions.

Example:

#include <iostream.h>

Int globalResult=0; //global variable

int main()

{

Int localVar = 10; //local variable.

…..

 

}

Related questions

+1 vote
asked May 19, 2021 in POSTMAN by rajeshsharma
0 votes
asked Jun 15, 2020 in C Plus Plus by Robindeniel
...