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
391
EN + हिं
GB What is 'template method pattern'?
IN 'टेम्पलेट विधि पैटर्न' क्या है?
A
Base class defines algorithm skeleton; derived classes fill in steps बेस क्लास एल्गोरिथम कंकाल को परिभाषित करता है; व्युत्पन्न कक्षाएं चरणों में भरती हैं
B
Using C++ templates C++ टेम्प्लेट का उपयोग करना
C
Method hiding छुपाने का तरीका
D
Copy elision एलीशन कॉपी करें
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Template Method: base class has a final method calling virtual steps that subclasses implement.
व्याख्या (हिन्दी) टेम्प्लेट विधि: बेस क्लास में वर्चुअल चरणों को कॉल करने की एक अंतिम विधि होती है जिसे उपवर्ग लागू करते हैं।
392
EN + हिं
GB What is the output: template struct Factorial{static const int value=N*Factorial::value;}; template<> struct Factorial<0>{static const int value=1;}; cout<::value;
IN आउटपुट क्या है: टेम्पलेट स्ट्रक्चर फ़ैक्टोरियल{static const int value=N*Factorial::value;}; टेम्प्लेट संरचना फ़ैक्टोरियल{स्थैतिक स्थिरांक पूर्णांक मान=1;}; अदालत
A
120 120
B
24 24
C
5 5
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) TMP factorial: 5*4*3*2*1=120. Computed at compile time. Output: 120.
व्याख्या (हिन्दी) टीएमपी फैक्टोरियल: 5*4*3*2*1=120। संकलन समय पर गणना की गई। आउटपुट: 120.
393
EN + हिं
GB What is 'std::any' in C++17?
IN C++17 में 'std::any' क्या है?
A
Type-safe container for single value of any type किसी भी प्रकार के एकल मान के लिए टाइप-सुरक्षित कंटेनर
B
Type erasure for any callable किसी भी कॉल करने योग्य के लिए इरेज़र टाइप करें
C
Universal base class यूनिवर्सल बेस क्लास
D
Void pointer wrapper शून्य सूचक आवरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) std::any holds a value of any type with type safety; use std::any_cast to retrieve the value.
व्याख्या (हिन्दी) std::any प्रकार की सुरक्षा के साथ किसी भी प्रकार का मान रखता है; मान पुनर्प्राप्त करने के लिए std::any_cast का उपयोग करें।
394
EN + हिं
GB What is 'abstraction vs implementation' tradeoff?
IN 'अमूर्तीकरण बनाम कार्यान्वयन' समझौता क्या है?
A
More abstraction: flexibility + overhead; less: efficiency + rigidity अधिक अमूर्तता: लचीलापन + ओवरहेड; कम: दक्षता + कठोरता
B
More abstraction is always better अधिक अमूर्तता सदैव बेहतर होती है
C
Implementation details are irrelevant कार्यान्वयन विवरण अप्रासंगिक हैं
D
No tradeoff exists कोई समझौता मौजूद नहीं है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Abstraction enables flexibility and reuse but may incur overhead (virtual dispatch, indirection); direct implementation is faster but less flexible.
व्याख्या (हिन्दी) अमूर्तन लचीलेपन और पुन: उपयोग को सक्षम बनाता है लेकिन ओवरहेड (आभासी प्रेषण, अप्रत्यक्ष) हो सकता है; प्रत्यक्ष कार्यान्वयन तेज़ है लेकिन कम लचीला है।
395
EN + हिं
GB What is the output: class Base{public: void interface(){impl();} private: virtual void impl(){cout<<'B';}}; class Der:public Base{private: void impl()override{cout<<'D';}}; Der d; d.interface();
IN आउटपुट क्या है: क्लास बेस {सार्वजनिक: शून्य इंटरफ़ेस() {impl();} निजी: वर्चुअल शून्य impl() {cout
A
B बी
B
D डी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) NVI (Non-Virtual Interface): interface() calls virtual impl(). Der overrides impl(). Output: D.
व्याख्या (हिन्दी) एनवीआई (नॉन-वर्चुअल इंटरफ़ेस): इंटरफ़ेस() वर्चुअल इम्प्ल() को कॉल करता है। डेर impl() को ओवरराइड करता है। आउटपुट: डी.
396
EN + हिं
GB What is 'non-virtual interface' (NVI) pattern?
IN 'नॉन-वर्चुअल इंटरफ़ेस' (एनवीआई) पैटर्न क्या है?
A
Public non-virtual function calls private virtual customization point सार्वजनिक गैर-आभासी फ़ंक्शन निजी वर्चुअल अनुकूलन बिंदु को कॉल करता है
B
Hiding all virtual functions सभी आभासी कार्यों को छुपाया जा रहा है
C
Abstract base class pattern सार आधार वर्ग पैटर्न
D
CRTP variant सीआरटीपी वैरिएंट
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) NVI: public interface functions are non-virtual and call private virtual functions, giving base class control over customization.
व्याख्या (हिन्दी) एनवीआई: सार्वजनिक इंटरफ़ेस फ़ंक्शंस गैर-वर्चुअल हैं और निजी वर्चुअल फ़ंक्शंस को कॉल करते हैं, जो अनुकूलन पर बेस क्लास नियंत्रण प्रदान करते हैं।
397
EN + हिं
GB What is the output: struct Functor{int x; Functor(int v):x(v){} int operator()(int y){return x+y;}}; Functor f(10); cout<
IN आउटपुट क्या है: struct functor{int x; फ़ंक्टर(int v):x(v){} int ऑपरेटर()(int y){रिटर्न x+y;}}; फ़ंक्टर f(10); अदालत
A
15 15
B
10 10
C
5 5
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator() called with y=5: x+y=10+5=15. Output: 15.
व्याख्या (हिन्दी) ऑपरेटर() को y=5 के साथ कॉल किया जाता है: x+y=10+5=15। आउटपुट: 15.
398
EN + हिं
GB What is 'policy-based design'?
IN 'नीति-आधारित डिज़ाइन' क्या है?
A
Using template parameters to inject behavior at compile time संकलन समय पर व्यवहार को इंजेक्ट करने के लिए टेम्पलेट पैरामीटर का उपयोग करना
B
Runtime behavior injection रनटाइम व्यवहार इंजेक्शन
C
Abstract factory pattern सार फ़ैक्टरी पैटर्न
D
Dependency injection डिपेंडेंसी इंजेक्शन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Policy-based design uses templates to compose classes from orthogonal policies at compile time (Alexandrescu's Modern C++ Design).
व्याख्या (हिन्दी) नीति-आधारित डिज़ाइन संकलन समय पर ऑर्थोगोनल नीतियों से कक्षाएं बनाने के लिए टेम्पलेट्स का उपयोग करता है (अलेक्जेंड्रेस्कु का आधुनिक सी++ डिज़ाइन)।
399
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;}}; void g(A* a){a->f();} class B:public A{public: void f(){cout<<2;}}; g(new B);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls a->f() with virtual dispatch; B::f() returns 2. Output: 2.
व्याख्या (हिन्दी) g() वर्चुअल प्रेषण के साथ a->f() को कॉल करता है; B::f() रिटर्न 2. आउटपुट: 2.
400
EN + हिं
GB What is 'duck typing' concept in C++?
IN C++ में 'डक टाइपिंग' अवधारणा क्या है?
A
If it has the right interface, use it — achieved via templates यदि इसका इंटरफ़ेस सही है, तो इसका उपयोग करें - टेम्प्लेट के माध्यम से प्राप्त किया गया
B
Runtime type checking रनटाइम प्रकार की जाँच
C
Dynamic_cast usage डायनामिक_कास्ट उपयोग
D
Virtual function tables वर्चुअल फ़ंक्शन टेबल
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Templates achieve duck typing: if type T has the required operations, the template compiles — no explicit interface needed.
व्याख्या (हिन्दी) टेम्प्लेट डक टाइपिंग प्राप्त करते हैं: यदि टाइप टी में आवश्यक संचालन हैं, तो टेम्प्लेट संकलित होता है - किसी स्पष्ट इंटरफ़ेस की आवश्यकता नहीं है।
401
EN + हिं
GB What is the output: template void print(T v){cout<
IN आउटपुट क्या है: टेम्पलेट शून्य प्रिंट (टी वी) {काउट
A
42A3.14 42ए3.14
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
42A3 42ए3
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Template instantiated for int, char, double. Outputs 42A3.14. Output: 42A3.14.
व्याख्या (हिन्दी) इंट, चार, डबल के लिए तत्काल टेम्पलेट। आउटपुट 42A3.14. आउटपुट: 42A3.14.
402
EN + हिं
GB What is the output: try{throw 42;}catch(int i){cout<
IN आउटपुट क्या है: Try{throw 42;}catch(int i){cout
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) throw 42 throws int; catch(int i) catches it; prints 42.
व्याख्या (हिन्दी) थ्रो 42 थ्रो इंट; पकड़ (int i) इसे पकड़ता है; प्रिंट 42.
403
EN + हिं
GB What happens when no catch handler matches a thrown exception?
IN क्या होता है जब कोई कैच हैंडलर फेंके गए अपवाद से मेल नहीं खाता?
A
Program continues कार्यक्रम जारी है
B
std::terminate is called std::terminet कहा जाता है
C
Exception is silently ignored अपवाद को चुपचाप नजरअंदाज कर दिया जाता है
D
Default catch is used डिफ़ॉल्ट कैच का उपयोग किया जाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If no handler matches (and no catch-all ...), std::terminate() is called, ending the program.
व्याख्या (हिन्दी) यदि कोई हैंडलर मेल नहीं खाता (और कोई कैच-ऑल नहीं...), तो std::terminet() को कॉल किया जाता है, जिससे प्रोग्राम समाप्त हो जाता है।
404
EN + हिं
GB What is the output: try{try{throw 1.0;}catch(int){cout<<'I';}}catch(double){cout<<'D';}
IN आउटपुट क्या है: प्रयास करें {प्रयास करें {थ्रो 1.0;} पकड़ें (int) {काउट
A
I मैं
B
D डी
C
ID पहचान
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1.0 is double; inner catch(int) doesn't match; propagates to outer catch(double). Output: D.
व्याख्या (हिन्दी) 1.0 दोगुना है; आंतरिक कैच(इंट) मेल नहीं खाता; बाहरी कैच (डबल) तक फैलता है। आउटपुट: डी.
405
EN + हिं
GB What is 'exception safety guarantee'?
IN 'अपवाद सुरक्षा गारंटी' क्या है?
A
Level of guarantee a function provides about state when exception thrown अपवाद फेंके जाने पर कोई फ़ंक्शन स्थिति के बारे में गारंटी का स्तर प्रदान करता है
B
Catching all exceptions सभी अपवादों को पकड़ना
C
noexcept specification विशिष्टता को छोड़कर कोई नहीं
D
Stack unwinding ढेर खोलना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Levels: basic (no leak), strong (transaction), nothrow (never throws). Exception safety is about invariant preservation.
व्याख्या (हिन्दी) स्तर: बुनियादी (कोई रिसाव नहीं), मजबूत (लेन-देन), नोथ्रो (कभी नहीं फेंकता)। अपवाद सुरक्षा अपरिवर्तनीय संरक्षण के बारे में है।
391–405 of 1915