Pages

Sunday, May 11, 2025

Static keyword : Static Object in OOPs

#include <iostream>
using namespace std;

class Example {
public:
    Example() {
        cout << "constructor..\n";
    }

    ~Example() {
        cout << "destructor..\n";
    }
};


int main() {
    int a = 0;
    if(a == 0) {
        static Example eg1;
    }

    cout << "code ending..\n";


    return 0;

} 


output:

constructor..

code ending..

destructor..

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...