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

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...