Skip to content
Related Articles

Related Articles

C++ | Constructors | Question 10

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 02 Dec, 2021




<br>
#include < iostream ><br>
using namespace std;<br><br>
  
class Test<br>
{<br>
public:<br>
Test() { cout << "Hello from Test() "; }<br>
} a;<br><br>
  
int main()<br>
{<br>
cout << "Main Started ";<br>
return 0;<br>
}

(A) Main Started
(B) Main Started Hello from Test()
(C) Hello from Test() Main Started
(D) Compiler Error: Global objects are not allowed


Answer: (C)

Explanation: Output is

Hello from Test() Main Started

There is a global object ‘a’ which is constructed before the main functions starts, so the constructor for a is called first, then main()’ execution begins.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!