Files
CS-Classes/CS202/static.cpp
2025-06-17 14:42:22 -07:00

34 lines
487 B
C++

#include <iostream>
//using namespace std;
void func1(){
static int x = 5;
x += 1;
std::cout << "Func1: " << x << std::endl;
}
void func2(){
int x = 5;
x += 1;
std::cout << "Func2: " << x << std::endl;
}
int main() {
func1();
func1();
func1();
func2();
func2();
func2();
func1();
}
//the static variable is initialized and effected only once.
//Static Memory Allocation != static members.
//Dynamic Memory Allocation