My C++ Quiz

The ultimate place to learn C++!

Question #68: What gets printed?

#include <iostream>

struct A
{
  A() : val(0) {}
  A(int v) : val(v) {}
  A(A& a) : val(a.val) {} 

  int val;
};

int main(int argc, char** argv)
{
  const A a1;
  const A a2(5);
  const A a3 = a2;

  std::cout << a1.val + a2.val + a3.val << std::endl;

  return 0;
}