A local variable is initialized each time its block is entered : function scope variables « Function « C++ Tutorial






#include <iostream> 
using namespace std; 
 
void f(); 
 
int main() 
{ 
   
  for(int i=0; i < 3; i++) f(); 
   
  return 0; 
} 
 
// num is initialized each time f() is called. 
void f() 
{ 
  int num = 99; 
 
  cout << num << "\n"; 
 
  num++; // this has no lasting effect 
}
99
99
99








7.15.function scope variables
7.15.1.Function level variable
7.15.2.A local variable is initialized each time its block is entered