OOP Using C++ — MCQ Practice

Hindi aur English dono mein practice karo — click karo answer check karne ke liye

📚 1915 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
1915 questions
256
EN + हिं
GB What is the output of destructor order for: class A{public:~A(){cout<<'A';}}; class B{A a; public:~B(){cout<<'B';}}; B b;
IN डिस्ट्रक्टर ऑर्डर का आउटपुट क्या है: क्लास ए{पब्लिक:~ए(){काउट
A
AB अब
B
BA बी ० ए
C
A
D
B बी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B's destructor body runs first (prints B), then member a's destructor runs (prints A). Wait — destructor body of B runs first then member destructors. Output: BA. Correcting: B::~B body runs (cout<<'B'), then A::~A runs (cout<<'A'). Output: BA.
व्याख्या (हिन्दी) बी का डिस्ट्रक्टर बॉडी पहले चलता है (बी को प्रिंट करता है), फिर सदस्य ए का डिस्ट्रक्टर चलता है (ए को प्रिंट करता है)। रुको - बी का विध्वंसक निकाय पहले चलता है फिर सदस्य विध्वंसक। आउटपुट: बी.ए. सुधार: बी::~बी बॉडी रन (काउट)।
257
EN + हिं
GB What is 'member initializer list'?
IN 'सदस्य आरंभकर्ता सूची' क्या है?
A
Syntax for initializing members before constructor body कंस्ट्रक्टर बॉडी से पहले सदस्यों को आरंभ करने के लिए सिंटैक्स
B
List of member functions सदस्य कार्यों की सूची
C
Default values in header हेडर में डिफ़ॉल्ट मान
D
Runtime initialization रनटाइम आरंभीकरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(int x): member(x){} — initializes member before constructor body executes; required for const/reference members.
व्याख्या (हिन्दी) A(int x): सदस्य(x){} - कंस्ट्रक्टर बॉडी निष्पादित होने से पहले सदस्य को आरंभ करता है; कॉन्स्ट/संदर्भ सदस्यों के लिए आवश्यक।
258
EN + हिं
GB What is the output: class A{public: int x; A(int v):x(v){cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v):x(v){cout
A
3-3 3-3
B
33 33
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints 3, destructor prints -3. Output: 3-3.
व्याख्या (हिन्दी) कंस्ट्रक्टर प्रिंट 3, डिस्ट्रक्टर प्रिंट -3। आउटपुट: 3-3.
259
EN + हिं
GB When is default constructor automatically generated?
IN डिफ़ॉल्ट कंस्ट्रक्टर स्वचालित रूप से कब उत्पन्न होता है?
A
When no user-defined constructor exists जब कोई उपयोगकर्ता-परिभाषित कंस्ट्रक्टर मौजूद नहीं है
B
Always हमेशा
C
Only for POD types केवल POD प्रकारों के लिए
D
When class has virtual functions जब क्लास में वर्चुअल फ़ंक्शन हों
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) The compiler generates a default constructor only if no user-defined constructors are declared.
व्याख्या (हिन्दी) कंपाइलर एक डिफ़ॉल्ट कंस्ट्रक्टर तभी उत्पन्न करता है जब कोई उपयोगकर्ता-परिभाषित कंस्ट्रक्टर घोषित नहीं किया जाता है।
260
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';} A(A&&){cout<<'M';} ~A(){cout<<'D';}}; A f(){return A();} A a=f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
AD विज्ञापन
B
A
C
AMD एएमडी
D
AM पूर्वाह्न
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) With mandatory copy elision (C++17), return A() creates the object directly in a; only one constructor call. Output: A (then D at end but question asks for output which includes D): actually output includes D at scope end. AD.
व्याख्या (हिन्दी) अनिवार्य कॉपी एलिज़न (सी++17) के साथ, रिटर्न ए() ऑब्जेक्ट को सीधे ए में बनाता है; केवल एक कंस्ट्रक्टर कॉल। आउटपुट: ए (फिर अंत में डी लेकिन प्रश्न आउटपुट के लिए पूछता है जिसमें डी शामिल है): वास्तव में आउटपुट में स्कोप के अंत में डी शामिल है। ई.पू.
261
EN + हिं
GB What is the output: class A{int x; public: A(int v=5):x(v){} ~A(){cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v=5):x(v){} ~A(){cout
A
53 53
B
35 35
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a uses default x=5, b uses x=3. Destructors called in reverse: ~b(3) prints 3, ~a(5) prints 5. Output: 35.
व्याख्या (हिन्दी) a डिफ़ॉल्ट x=5 का उपयोग करता है, b x=3 का उपयोग करता है। डिस्ट्रक्टर्स को रिवर्स में बुलाया गया: ~बी(3) प्रिंट 3, ~ए(5) प्रिंट 5। आउटपुट: 35।
262
EN + हिं
GB What is 'virtual destructor'?
IN 'वर्चुअल डिस्ट्रक्टर' क्या है?
A
Destructor called via vtable for proper derived class cleanup उचित व्युत्पन्न क्लास क्लीनअप के लिए डिस्ट्रक्टर को vtable के माध्यम से बुलाया गया
B
Destructor that can be overridden विध्वंसक जिसे ओवरराइड किया जा सकता है
C
Pure virtual destructor शुद्ध आभासी विध्वंसक
D
Destructor for abstract class only केवल अमूर्त वर्ग के लिए विध्वंसक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Making base class destructor virtual ensures the derived class destructor is called when deleting through a base pointer.
व्याख्या (हिन्दी) बेस क्लास डिस्ट्रक्टर को वर्चुअल बनाना सुनिश्चित करता है कि बेस पॉइंटर के माध्यम से हटाते समय व्युत्पन्न क्लास डिस्ट्रक्टर को कॉल किया जाता है।
263
EN + हिं
GB What is the output: class A{public: A(int){cout<<'P';} A(){cout<<'D';}}; A a; A b(1);
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए (इंट) {काउट
A
DP डी पी
B
PD पी.डी.
C
DD डीडी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a calls default ctor (D), b(1) calls int ctor (P). Output: DP.
व्याख्या (हिन्दी) a डिफ़ॉल्ट ctor (D) को कॉल करता है, b(1) int ctor (P) को कॉल करता है। आउटपुट: डीपी.
264
EN + हिं
GB What is the output: class B{public:~B(){cout<<'B';}}; class D:public B{public:~D(){cout<<'D';}}; B*p=new D; delete p;
IN आउटपुट क्या है: क्लास बी{पब्लिक:~बी(){काउट
A
DB डाटाबेस
B
B बी
C
Undefined behavior (memory leak possible) अपरिभाषित व्यवहार (स्मृति रिसाव संभव)
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Deleting derived object through non-virtual base pointer is undefined behavior; D's destructor may not be called.
व्याख्या (हिन्दी) गैर-वर्चुअल बेस पॉइंटर के माध्यम से व्युत्पन्न ऑब्जेक्ट को हटाना अपरिभाषित व्यवहार है; डी के विध्वंसक को नहीं बुलाया जा सकता है।
265
EN + हिं
GB What is 'RAII constructor'?
IN 'RAII कंस्ट्रक्टर' क्या है?
A
Constructor that acquires resources कंस्ट्रक्टर जो संसाधन प्राप्त करता है
B
Default constructor डिफ़ॉल्ट कंस्ट्रक्टर
C
Copy constructor कंस्ट्रक्टर कॉपी करें
D
Template constructor टेम्प्लेट कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) In RAII, the constructor acquires a resource (file, lock, memory) and the destructor releases it.
व्याख्या (हिन्दी) RAII में, कंस्ट्रक्टर एक संसाधन (फ़ाइल, लॉक, मेमोरी) प्राप्त करता है और डिस्ट्रक्टर इसे जारी करता है।
266
EN + हिं
GB What is the output: class A{public: A(){x=++c;} static int c; int x;}; int A::c=0; A a,b,c; cout<
IN आउटपुट क्या है: class A{public: A(){x=++c;} static int c; int x;}; int A::c=0; ए ए, बी, सी; अदालत
A
123 123
B
321 321
C
111 111
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each constructor increments static c: a.x=1, b.x=2, c.x=3. Output: 123.
व्याख्या (हिन्दी) प्रत्येक कंस्ट्रक्टर स्थिर c बढ़ाता है: a.x=1, b.x=2, c.x=3। आउटपुट: 123.
267
EN + हिं
GB What is a 'converting constructor'?
IN 'कन्वर्टिंग कंस्ट्रक्टर' क्या है?
A
Constructor enabling implicit type conversion अंतर्निहित प्रकार के रूपांतरण को सक्षम करने वाला कंस्ट्रक्टर
B
Constructor for type casting टाइप कास्टिंग के लिए कंस्ट्रक्टर
C
Explicit constructor स्पष्ट निर्माता
D
Copy constructor कंस्ट्रक्टर कॉपी करें
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A constructor callable with a single argument that enables implicit conversion from that argument type to the class type.
व्याख्या (हिन्दी) एकल तर्क के साथ कॉल करने योग्य एक कंस्ट्रक्टर जो उस तर्क प्रकार से क्लास प्रकार में अंतर्निहित रूपांतरण को सक्षम बनाता है।
268
EN + हिं
GB What is the output: class A{public: ~A(){cout<<'X';}}; A *p=new A[3]; delete[] p;
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: ~ ए() {काउट
A
X एक्स
B
XXX XXX
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete[] calls destructor for each of 3 elements. Output: XXX.
व्याख्या (हिन्दी) delete[] प्रत्येक 3 तत्वों के लिए डिस्ट्रक्टर को कॉल करता है। आउटपुट: XXX.
269
EN + हिं
GB What happens if constructor throws an exception?
IN यदि कंस्ट्रक्टर अपवाद फेंकता है तो क्या होता है?
A
Object is partially constructed; destructor NOT called वस्तु आंशिक रूप से निर्मित है; विध्वंसक को नहीं बुलाया गया
B
Destructor is called संहारक कहा जाता है
C
Program terminates कार्यक्रम समाप्त
D
Exception is suppressed अपवाद दबा दिया गया है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If constructor throws, the object is not fully constructed so its destructor is not called. Already-initialized member destructors are called.
व्याख्या (हिन्दी) यदि कंस्ट्रक्टर थ्रो करता है, तो ऑब्जेक्ट पूरी तरह से निर्मित नहीं होता है इसलिए उसके डिस्ट्रक्टर को नहीं बुलाया जाता है। पहले से आरंभ किए गए सदस्य विध्वंसक कहलाते हैं।
270
EN + हिं
GB What is the output: class A{public: A(int x){cout<
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए (इंट एक्स) {काउट
A
5C 5सी
B
5 5
C
CC सीसी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) obj(5): prints 5. f(obj): passes by value, copy constructor called, prints C. Output: 5C.
व्याख्या (हिन्दी) obj(5): प्रिंट 5. f(obj): मान से गुजरता है, कॉपी कंस्ट्रक्टर को बुलाया जाता है, C प्रिंट करता है। आउटपुट: 5C।
256–270 of 1915