Two different local variables with the same name. - C++ Function

C++ examples for Function:Function Creation

Description

Two different local variables with the same name.

Demo Code

#include <iostream>
using namespace std;
int get_age();  // Prototype
int main()//  ww w  .  j  a va  2s  . c  o  m
{
   int age;
   cout << "What is your age? ";
   cin >> age;
   get_age();                 // Call the second function.
   cout << "main()'s age is still " << age << "\n";
   return 0;
}
int get_age()
{
   int age;                
   cout << "What is your age again? ";
   cin >> age;
   return 0;
}

Result


Related Tutorials