What term is used to describe the portion of a program in which a variable can be accessed?

In general, the scope is defined as the extent up to which something can be worked with. In programming also the scope of a variable is defined as the extent of the program code within which the variable can be accessed or declared or worked with. There are mainly two types of variable scopes: 

  1. Local Variables
  2. Global Variables

Now let’s understand each of the scope at a greater detail: 
 

Local Variables

Variables defined within a function or block are said to be local to those functions.  

  • Anything between ‘{‘ and ‘}’ is said to inside a block.
  • Local variables do not exist outside the block in which they are declared, i.e. they can not be accessed or used outside that block.
  • Declaring local variables: Local variables are declared inside a block.

C++

#include

using namespace std;

void func[]

{  

    int age=18;   

}

int main[]

{

    cout

Chủ Đề