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
Зарегистрируйся сейчас
или Подпишись на будущие тесты