C++ Variable Local Scope

Introduction

When we declare a name inside a function, that name has a local scope.

Its scope starts from the point of declaration till the end of the function block marked with }.

Example:

void myfunction() 
{ 

    int x = 123; // Here begins the x's scope 

} // and here it ends 

Our variable x is declared inside a myfunction() body, and it has a local scope.

We say that name x is local to myfunction().

It exists (can be accessed) only inside the function's scope and nowhere else.




PreviousNext

Related