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

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

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