Uses both local and global variables. - C++ Function

C++ examples for Function:Global Variable

Description

Uses both local and global variables.

Demo Code

// Local Variables       Global Variables
//     j, p                   i, z
#include <iostream>
using namespace std;
int pr_again();  // Prototype
int i = 0;                // Global variable because it's defined outside main().
int main()//from   w  w w.jav a  2  s  .  c  om
{
   float p ;                      
   p = 9.0;               
   cout << i << ", " << p << "\n";   
   pr_again();                    
   return 0;                      
}
float z = 9.0;            
int pr_again()
{
   int j = 5;             
   cout << j << ", " << z; 
   cout << ", " << i << "\n";
   return 0;               
}

Result


Related Tutorials