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
Get an explanation when it's available:
C++
C++ Quiz
Start Quiz

or Read more about C++ Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback