What will be the result of the program?
#include <iostream>

class Clazz {
public:
   int Anton;
   int Kris;
   int Denis;

   Clazz(int a)
      : Anton(++a)
      , Denis(++a)
      , Kris(++a)
   {
   }
};

int main(int argc, char *argv[]) {
   static int a;
   Clazz x(a);
   std::cout << x.Anton << x.Denis << x.Kris;
}
Explanation
1. Static variables are always initialized with zero by default.
2. Class fields are initialized in the order of their declaration in the class code, not in the order of constructors declaration.

Follow CodeGalaxy

Mobile Beta

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