C-programming - Local variables, C++ local variables

Local variables

Local Variable

A local variable is a variable that is given local scope ie a variable is accessible only from the function or block in which it is declared. Local variables must always be defined at the top of a block.

#include <iostream.h>
   int local()
       int a;
       a = 500;
       return x;
   int main( )
       int a;
       a = 250;
       cout  <<  "a in  main is:" <<  a  << '\n';    
       cout  <<  "a in  local is:" <<  local()  << '\n';    
       return 0;


a in main is: 250
a in local is : 500

In both the functions a is declared as local variable

The topic on C-programming - Local variables is posted by - Sathya

Hope you have enjoyed, C-programming - Local variablesThanks for your time

Tech Bluff