Pages

Sunday, May 11, 2025

Static Keyword - Static Variables in OOPs

 #include <iostream>

using namespace std;

void counter() {
    static int count = 0; // Static Variable

    count++;
    cout << "count : " << count << endl;
};

int main() {
    counter();
    counter();
    counter();

    return 0;
}

output:
count : 1
count : 2
count : 3

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...