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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...