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
271
EN + हिं
GB What is 'move constructor'?
IN 'मूव कंस्ट्रक्टर' क्या है?
A
Constructor transferring resources from rvalue कंस्ट्रक्टर प्रतिद्वंद्विता से संसाधनों को स्थानांतरित कर रहा है
B
Copy constructor कंस्ट्रक्टर कॉपी करें
C
Default constructor डिफ़ॉल्ट कंस्ट्रक्टर
D
Delegating constructor प्रतिनिधि निर्माणकर्ता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Move constructor A(A&&) steals resources from a temporary (rvalue) instead of copying them.
व्याख्या (हिन्दी) मूव कंस्ट्रक्टर A(A&&) संसाधनों को कॉपी करने के बजाय अस्थायी (प्रतिद्वंद्विता) से चुराता है।
272
EN + हिं
GB What is the output: class A{public: A(){cout<<'N';} A(int){cout<<'I';} A(double){cout<<'D';}}; A a(1), b(1.0), c;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
IDA आईडीए
B
IDN आईडीएन
C
NID एनआईडी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a(1): int ctor=I. b(1.0): double ctor=D. c: default ctor=N. Output: IDN.
व्याख्या (हिन्दी) a(1): int ctor=I. b(1.0): डबल ctor=D. सी: डिफ़ॉल्ट ctor=N. आउटपुट: आईडीएन.
273
EN + हिं
GB What is the output: class A{public: int x=0; A()=default;}; A a{}; cout<
IN आउटपुट क्या है: class A{public: int x=0; ए()=डिफ़ॉल्ट;}; ए ए{}; अदालत
B
Undefined अपरिभाषित
C
1 1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default constructor with in-class initializer: x=0. Output: 0.
व्याख्या (हिन्दी) इन-क्लास इनिशियलाइज़र के साथ डिफ़ॉल्ट कंस्ट्रक्टर: x=0। आउटपुट: 0.
274
EN + हिं
GB What is 'Rule of Five' in C++11?
IN C++11 में 'पांच का नियम' क्या है?
A
Define all 5: destructor, copy-ctor, copy-assign, move-ctor, move-assign सभी 5 को परिभाषित करें: डिस्ट्रक्टर, कॉपी-क्टर, कॉपी-असाइन, मूव-क्टर, मूव-असाइन
B
5 virtual functions 5 आभासी कार्य
C
5 inheritance levels 5 वंशानुक्रम स्तर
D
5 constructors 5 कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Rule of Five extends Rule of Three with move constructor and move assignment operator for C++11.
व्याख्या (हिन्दी) पाँच का नियम C++11 के लिए मूव कंस्ट्रक्टर और मूव असाइनमेंट ऑपरेटर के साथ तीन के नियम का विस्तार करता है।
275
EN + हिं
GB What is the output: class A{public: A(){cout<<'B';} ~A(){cout<<'E';} void f(){cout<<'M';}}; A a; a.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
BME बीएमई
B
BEM कार्यलय
C
Compile error संकलन त्रुटि
D
BE होना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints B, f() prints M, destructor prints E at end of scope. Output: BME.
व्याख्या (हिन्दी) कंस्ट्रक्टर बी प्रिंट करता है, एफ() प्रिंट एम, डिस्ट्रक्टर स्कोप के अंत में ई प्रिंट करता है। आउटपुट: बीएमई.
276
EN + हिं
GB When are destructors called in reverse order?
IN विध्वंसकों को उल्टे क्रम में कब बुलाया जाता है?
A
For objects declared in same scope समान दायरे में घोषित वस्तुओं के लिए
B
For base and derived classes आधार और व्युत्पन्न वर्गों के लिए
C
For array elements सरणी तत्वों के लिए
D
All of the above ऊपर के सभी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Destructors are called in reverse order of construction for objects in the same scope, array elements (reverse index), and derived/base class (derived first).
व्याख्या (हिन्दी) विनाशकों को समान दायरे, सरणी तत्वों (रिवर्स इंडेक्स), और व्युत्पन्न/आधार वर्ग (पहले व्युत्पन्न) में वस्तुओं के लिए निर्माण के विपरीत क्रम में बुलाया जाता है।
277
EN + हिं
GB What is the output: class A{int x; public: explicit A(int v):x(v){} int get()const{return x;}}; A a=A(5); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: स्पष्ट A(int v):x(v){} int get()const{return x;}}; ए ए=ए(5); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(5) is direct initialization; explicit prevents implicit conversion but direct is fine. a.get()=5.
व्याख्या (हिन्दी) ए(5) प्रत्यक्ष आरंभीकरण है; स्पष्ट रूप से अंतर्निहित रूपांतरण को रोकता है लेकिन प्रत्यक्ष ठीक है। a.get()=5.
278
EN + हिं
GB What is the output: class A{public: A(int x=10,int y=20){cout<
IN आउटपुट क्या है: वर्ग A{सार्वजनिक: A(int x=10,int y=20){cout
A
303011 303011
B
302511 302511
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a: 10+20=30, b(5): 5+20=25, c(5,6): 5+6=11. Output: 302511.
व्याख्या (हिन्दी) ए: 10+20=30, बी(5): 5+20=25, सी(5,6): 5+6=11। आउटपुट: 302511.
279
EN + हिं
GB What is the output: class A{public: ~A()=delete;}; {A a;}
IN आउटपुट क्या है: क्लास ए{सार्वजनिक: ~ए()=डिलीट;}; {ए ए;}
A
Compile error संकलन त्रुटि
B
Undefined अपरिभाषित
C
A
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Deleting destructor prevents any object with automatic storage duration; compile error.
व्याख्या (हिन्दी) विध्वंसक को हटाने से स्वचालित भंडारण अवधि वाली किसी भी वस्तु को रोका जा सकता है; संकलन त्रुटि.
280
EN + हिं
GB What is 'trivial destructor'?
IN 'तुच्छ विध्वंसक' क्या है?
A
Destructor that does nothing and is compiler-generated डिस्ट्रक्टर जो कुछ नहीं करता है और कंपाइलर-जनरेटेड है
B
Empty user-defined destructor उपयोगकर्ता-परिभाषित विध्वंसक को खाली करें
C
Virtual destructor आभासी विध्वंसक
D
Static destructor स्थैतिक विध्वंसक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A trivial destructor is implicitly defined, does nothing, and allows objects to be destroyed without calling it (e.g., via free()).
व्याख्या (हिन्दी) एक तुच्छ विध्वंसक को स्पष्ट रूप से परिभाषित किया गया है, कुछ भी नहीं करता है, और वस्तुओं को बिना कॉल किए नष्ट करने की अनुमति देता है (उदाहरण के लिए, free() के माध्यम से)।
281
EN + हिं
GB What is the output: class A{public: A(){cout<<1;} A(const A&){cout<<2;} ~A(){cout<<3;}}; A f(A a){return a;} A b; f(b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
1 2 3 2 3 3 (numbers) 1 2 3 2 3 3 (संख्याएँ)
B
123233 123233
C
Depends on optimization अनुकूलन पर निर्भर करता है
D
12233 12233
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) With NRVO and copy elision, actual output depends on optimization level. Without optimization: construct b(1), copy to a(2), copy return(2), destroy return(3), destroy a(3), eventually destroy b(3). Output varies with optimization.
व्याख्या (हिन्दी) एनआरवीओ और कॉपी एलिज़न के साथ, वास्तविक आउटपुट अनुकूलन स्तर पर निर्भर करता है। अनुकूलन के बिना: b(1) बनाएं, a(2) में कॉपी करें, रिटर्न कॉपी करें(2), रिटर्न नष्ट करें(3), a(3) नष्ट करें, अंततः b(3) नष्ट करें। आउटपुट अनुकूलन के साथ बदलता रहता है।
282
EN + हिं
GB What is the output: class A{public: void f(){cout<<'A';}}; class B:public A{public: void f(){cout<<'B';}}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() hides A::f(). b.f() calls B's version. Output: B.
व्याख्या (हिन्दी) B::f() A::f() को छुपाता है। b.f() B के संस्करण को कॉल करता है। आउटपुट: बी.
283
EN + हिं
GB What is 'diamond problem' in C++?
IN C++ में 'डायमंड प्रॉब्लम' क्या है?
A
Ambiguity when class inherits from two classes sharing a base अस्पष्टता जब वर्ग को आधार साझा करने वाले दो वर्गों से विरासत मिलती है
B
Memory diamond shape स्मृति हीरे का आकार
C
Multiple constructors एकाधिक निर्माणकर्ता
D
Template diamond टेम्पलेट हीरा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Diamond problem: D inherits B and C, both inherit A. D has two copies of A unless virtual inheritance is used.
व्याख्या (हिन्दी) हीरे की समस्या: D को B और C विरासत में मिले हैं, दोनों को A विरासत में मिला है। D के पास A की दो प्रतियां हैं जब तक कि आभासी विरासत का उपयोग नहीं किया जाता है।
284
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';}}; class B:public A{public: B(){cout<<'B';}}; class C:public B{public: C(){cout<<'C';}}; C c;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
CBA सीबीए
B
ABC एबीसी
C
BAC बीएसी
D
CAB कैब
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Base classes constructed first (top-down): A then B then C. Output: ABC.
व्याख्या (हिन्दी) बेस क्लास का निर्माण पहले (ऊपर से नीचे): ए, फिर बी, फिर सी। आउटपुट: एबीसी।
285
EN + हिं
GB What is virtual inheritance?
IN आभासी विरासत क्या है?
A
Ensures single base class instance in diamond inheritance हीरे की विरासत में एकल आधार वर्ग उदाहरण सुनिश्चित करता है
B
Virtual function inheritance वर्चुअल फ़ंक्शन इनहेरिटेंस
C
Pure virtual class शुद्ध आभासी कक्षा
D
Multiple inheritance एकाधिक वंशानुक्रम
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) virtual inheritance prevents multiple copies of base class in diamond hierarchy by sharing a single base instance.
व्याख्या (हिन्दी) वर्चुअल इनहेरिटेंस एकल बेस इंस्टेंस को साझा करके डायमंड पदानुक्रम में बेस क्लास की कई प्रतियों को रोकता है।
271–285 of 1915