What will be printed out as a result of the following code execution?

#include <iostream>
class A {
public:
    int k;
    void SetCount() {
        static int n = 0;
        k = n++;
    };
};

int main() {
    A *pA = new A();
    pA->SetCount();
    std::cout<<pA->k;
    delete pA;

    pA = new A();
    pA->SetCount();
    std::cout<<pA->k;

    A a;
    a.SetCount();
    std::cout<<a.k;
    delete pA;

    return 0;
}
Explanation
Despite the fact that objects and pointers to objects of class A destroyed in main() static members still exists and could be accessed and changed

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести