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

#include <iostream>
using namespace std;

struct SomeType {
    void someMethod();
    static int cnt;
};

int SomeType::cnt;

void SomeType::someMethod() {
   cout << "cnt" << cnt;
   ++cnt;
 }

int main() {
  SomeType someVar;
  SomeType *ptrSomeType = new SomeType();      
  (*ptrSomeType).someMethod(); 
  delete ptrSomeType;
  (&someVar)->someMethod();          
  return 0;
}
Explanation
Static variables (global, local, members of the class etc.) are always initialized with zero. (*ptrSomeType).someMethod(); and (&someVar)->someMethod(); calls are equivalent.
C++
C++ Quiz
Start Quiz

or Read more about C++ Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback