Variable Scope Example
#include <iostream>
using namespace std;
int subtract (int a, int b);
int global = 5;
int main(void)
{
int a, b;
a = 5;
b = 3;
cout << "The value of main's a is: " << a << endl
<< "The value of main's b is: " << b << endl
<< "The value of global is: " << global << endl;
global = 2 + subtract(a,b);
cout << "The value of main's a now is: " << a << endl
<< "The value of global now is: " << global << endl;
return 0;
}
int subtract(int a, int b)
{
cout << "The value of subtract's a is: " << a << endl
<< "The value of subtract's b is: " << b << endl;
a = a - b + global;
return a;
}
Related examples in the same category