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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...