Mega Code Archive

 
Categories / C++ / Function
 

Effect of scope on automatic variables

#include <iostream> using namespace std; int main() {                         int count1 = 10;    int count3 = 50;        cout << "Value of outer count1 = " << count1 << endl;    {                         int count1 = 20;       int count2 = 30;       cout << "Value of inner count1 = " << count1 << endl;       count1 += 3;       count3 += count2;    }    cout << "Value of outer count1 = " << count1         << "Value of outer count3 = " << count3;    return 0; }