Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 2 : CCDCDMD

Advertisement

Detailed Solution

सही उत्तर CCDCDMD है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C++ program? class T { public: T() { cout << "C"; } ~T() { cout << "D"; } }; void g() { T t1; static T t2; } int main() { g(); g(); cout << "M"; } / निम्नलिखित C++ प्रोग्राम का आउटपुट क्या है?

1.
CCDDCCDDM
2.
CCDCDMD
3.
CCDMCCD
4.
CDCDMCD

Correct Answer: CCDCDMD

The first call of g() constructs t1 and the static t2 ("CC"), then destroys t1 ("D"). The second call constructs only t1 ("C") and destroys it ("D"). "M" is printed, and the static t2 is destroyed at program end ("D"), giving "CCDCDMD". / g() की पहली कॉल में t1 और static t2 बनते हैं ("CC"), फिर t1 नष्ट होता है ("D")। दूसरी कॉल में केवल t1 बनता ("C") और नष्ट होता है ("D")। "M" प्रिंट होता है, और static t2 प्रोग्राम समाप्ति पर नष्ट होता है ("D"), अतः "CCDCDMD" मिलता है।

Downloaded from PrepSnap (prepsnap.in)