OOP Using C++ — MCQ Practice

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

📚 107 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
107 questions
16
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.
17
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.
व्याख्या (हिन्दी) एकल तर्क के साथ कॉल करने योग्य एक कंस्ट्रक्टर जो उस तर्क प्रकार से क्लास प्रकार में अंतर्निहित रूपांतरण को सक्षम बनाता है।
18
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.
19
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.
व्याख्या (हिन्दी) यदि कंस्ट्रक्टर थ्रो करता है, तो ऑब्जेक्ट पूरी तरह से निर्मित नहीं होता है इसलिए उसके डिस्ट्रक्टर को नहीं बुलाया जाता है। पहले से आरंभ किए गए सदस्य विध्वंसक कहलाते हैं।
20
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।
21
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&&) संसाधनों को कॉपी करने के बजाय अस्थायी (प्रतिद्वंद्विता) से चुराता है।
22
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. आउटपुट: आईडीएन.
23
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.
24
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 के लिए मूव कंस्ट्रक्टर और मूव असाइनमेंट ऑपरेटर के साथ तीन के नियम का विस्तार करता है।
25
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.
व्याख्या (हिन्दी) कंस्ट्रक्टर बी प्रिंट करता है, एफ() प्रिंट एम, डिस्ट्रक्टर स्कोप के अंत में ई प्रिंट करता है। आउटपुट: बीएमई.
26
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).
व्याख्या (हिन्दी) विनाशकों को समान दायरे, सरणी तत्वों (रिवर्स इंडेक्स), और व्युत्पन्न/आधार वर्ग (पहले व्युत्पन्न) में वस्तुओं के लिए निर्माण के विपरीत क्रम में बुलाया जाता है।
27
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.
28
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.
29
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.
व्याख्या (हिन्दी) विध्वंसक को हटाने से स्वचालित भंडारण अवधि वाली किसी भी वस्तु को रोका जा सकता है; संकलन त्रुटि.
30
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() के माध्यम से)।
16–30 of 107