A

Admin • 833K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include<iostream>
using namespace std;

class MyClass
{
public:
MyClass();
};

MyClass::MyClass() {
cout << "Constructor is called
";
}

int main()
{
cout << " Before
";
MyClass myclass();
cout << " After
";
return 0;
}
  • (A) Before Constructor is called After
  • (B) Before After
  • (C) Constructor is called Before After
  • (D) None of the above.
  • Correct Answer - Option(B)
  • Views: 17
  • Filed under category C++
  • Hashtags:

Explanation by: Admin

Note that the line “MyClass maclass();” is not a constructor call. The compiler considers this line as a function declaration that receives no parameters and returns an object of type MyClass.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.