How to Define Local Variables in C++

Local variables have some limited access and the are only accessible within the scope of the function or block . Two Separate functions could have the same name local variables because they are unknown from outside of the function.

Source Code

#include<iostream>
using namespace std;
int main ()
{
 int num1,num2,num3;                 // declare the variables
 num1 =786, num2 =567;         // initialize the variables 
 num3=num1-num2;
 cout<<" \n Num1 is Local variable with values : "<<num1;
 cout<<" \n Num2 is Local variable with values : "<<num2;
 cout<<" \n \n  The Subtraction of these local variables is : "<<num3;
}

Output of the Program

Local Variables in C++



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment