#include <iostream.h>
/*************************************************************
An example to demonstrate the nature of static variables
Program: static_var.C
*************************************************************/
void fn();
void main(){
cout << "Calling fn()...\n";
fn();
cout << "\nCalling fn() again...\n";
fn();
}
void fn(){
static long x = 100;
long y = 100;
++x; //increments x
++y; //increments y
cout << "Inside fn()...\n";
cout << "x = " << x << "\n";
cout << "y = " << y << "\n";
}
Output:
Calling fn()...
Inside fn()...
x = 101
y = 101
Calling fn() again...
Inside fn()...
x = 102
y = 101
Back to Previous Page
Document:
Local Date:
Last Modified On: