C++ | Constructors | Question 15
#include<iostream> using namespace std; class Test { public: Test(); }; Test::Test() { cout << " Constructor Called. "; } void fun() { static Test t1; } int main() { cout << " Before fun() called. "; fun(); fun(); cout << " After fun() called. "; return 0; } |
chevron_right
filter_none
(A) Constructor Called. Before fun() called. After fun() called.
(B) Before fun() called. Constructor Called. Constructor Called. After fun() called.
(C) Before fun() called. Constructor Called. After fun() called.
(D) Constructor Called. Constructor Called. After fun() called.Before fun() called.
Answer: (C)
Explanation: Note that t is static in fun(), so constructor is called only once.
Quiz of this Question
Recommended Posts:
- C++ | Constructors | Question 17
- C++ | Constructors | Question 14
- 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 17
- C++ | Constructors | Question 9
- C++ | Constructors | Question 10
- C++ | Constructors | Question 1
- C++ | Constructors | Question 16
- C++ | Constructors | Question 12

