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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes