C++ | Constructors | Question 10
#include <iostream> using namespace std; class Test { public: Test() { cout << "Hello from Test() "; } } a; int main() { cout << "Main Started "; return 0; } |
chevron_right
filter_none
(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
Recommended Posts:
- C++ | Constructors | Question 12
- C++ | Constructors | Question 14
- C++ | Constructors | Question 17
- C++ | Constructors | Question 2
- C++ | Constructors | Question 3
- C++ | Constructors | Question 4
- C++ | Constructors | Question 5
- C++ | Constructors | Question 6
- C++ | Constructors | Question 7
- C++ | Constructors | Question 8
- C++ | Constructors | Question 9
- C++ | Constructors | Question 15
- C++ | Constructors | Question 16
- C++ | Constructors | Question 17
- C++ | Constructors | Question 1



