Skip to content
Related Articles

Related Articles

Improve Article
C++ | Constructors | Question 10
  • Difficulty Level : Basic
  • Last Updated : 01 Aug, 2013

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

(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

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :