OOP Using C++ — MCQ Practice

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

📚 123 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
123 questions
1
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.
2
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() को कॉल किया जाता है, जिससे प्रोग्राम समाप्त हो जाता है।
3
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 दोगुना है; आंतरिक कैच(इंट) मेल नहीं खाता; बाहरी कैच (डबल) तक फैलता है। आउटपुट: डी.
4
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.
व्याख्या (हिन्दी) स्तर: बुनियादी (कोई रिसाव नहीं), मजबूत (लेन-देन), नोथ्रो (कभी नहीं फेंकता)। अपवाद सुरक्षा अपरिवर्तनीय संरक्षण के बारे में है।
5
EN + हिं
GB What is the output: struct A{~A(){cout<<'D';}}; try{A a; throw 1;}catch(int){cout<<'C';}
IN आउटपुट क्या है: struct A{~A(){cout
A
CD सीडी
B
DC डीसी
C
C सी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Stack unwinding destroys a (prints D) before catch handler executes (prints C). Output: DC.
व्याख्या (हिन्दी) कैच हैंडलर निष्पादित (प्रिंट सी) से पहले स्टैक अनवाइंडिंग (प्रिंट डी) को नष्ट कर देता है। आउटपुट: डीसी.
6
EN + हिं
GB What is the output: try{throw;}catch(int){cout<<'I';}catch(...){cout<<'A';}
IN आउटपुट क्या है: प्रयास करें {फेंकें;} पकड़ें (int) {काउट
A
A
B
I मैं
C
std::terminate एसटीडी::समाप्त
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) throw; with no active exception calls std::terminate().
व्याख्या (हिन्दी) फेंक; बिना किसी सक्रिय अपवाद के std::termine() कॉल करता है।
7
EN + हिं
GB What is 'catch-all' handler in C++?
IN C++ में 'कैच-ऑल' हैंडलर क्या है?
A
catch(...) — catches any exception type पकड़ो(...) - किसी भी अपवाद प्रकार को पकड़ता है
B
catch(void) पकड़ना(शून्य)
C
catch(exception) पकड़ो (अपवाद)
D
Catching by value मूल्य के आधार पर पकड़ना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) catch(...) catches any exception type including non-class exceptions.
व्याख्या (हिन्दी) कैच(...) गैर-वर्ग अपवादों सहित किसी भी अपवाद प्रकार को पकड़ता है।
8
EN + हिं
GB What is the output: void f(){throw string("Error");} try{f();}catch(const string& s){cout<
IN आउटपुट क्या है: void f(){throw string("Error");} Try{f();}catch(const string& s){cout
A
Error गलती
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() throws string. catch catches by const ref, prints Error. Output: Error.
व्याख्या (हिन्दी) f() स्ट्रिंग फेंकता है। कॉन्स्ट रेफरी द्वारा कैच पकड़ें, त्रुटि प्रिंट करें। आउटपुट: त्रुटि.
9
EN + हिं
GB What is 'stack unwinding'?
IN 'स्टैक अनवाइंडिंग' क्या है?
A
Destructors called for local objects as exception propagates अपवाद प्रसार के रूप में विध्वंसकों ने स्थानीय वस्तुओं को बुलाया
B
Recursive function termination पुनरावर्ती कार्य समाप्ति
C
Stack overflow handling स्टैक ओवरफ्लो प्रबंधन
D
Memory deallocation मेमोरी डिलोकेशन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Stack unwinding: as exception propagates, destructors are called for all local objects in the chain of scopes.
व्याख्या (हिन्दी) स्टैक अनवाइंडिंग: जैसे-जैसे अपवाद फैलता है, स्कोप की श्रृंखला में सभी स्थानीय वस्तुओं के लिए डिस्ट्रक्टर्स को बुलाया जाता है।
10
EN + हिं
GB What is the output: class E{public: string msg; E(string s):msg(s){}}; try{throw E("Oops");}catch(E& e){cout<
IN आउटपुट क्या है: वर्ग ई {सार्वजनिक: स्ट्रिंग संदेश; ई(स्ट्रिंग s):msg(s){}}; प्रयास करें{फेंकें E("उफ़");}पकड़ें(E& e){cout
A
Oops उफ़
B
E
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) E(Oops) thrown and caught by reference. e.msg=Oops. Output: Oops.
व्याख्या (हिन्दी) ई(उफ़) संदर्भ द्वारा फेंका और पकड़ा गया। e.msg=उफ़. आउटपुट: उफ़.
11
EN + हिं
GB What is the output: try{throw 1;}catch(int& i){i=99; cout<
IN आउटपुट क्या है: Try{throw 1;}catch(int& i){i=99; अदालत
A
99 99
B
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) catch by reference; modify i=99; print i=99. Output: 99.
व्याख्या (हिन्दी) संदर्भ द्वारा पकड़ें; संशोधित करें i=99; i=99 प्रिंट करें। आउटपुट: 99.
12
EN + हिं
GB What is 'exception specification' in C++?
IN C++ में 'अपवाद विशिष्टता' क्या है?
A
noexcept or noexcept(expr) declaring function won't throw noexcept या noexcept(expr) घोषित करने वाला फ़ंक्शन नहीं फेंकेगा
B
throw() specification (deprecated) फेंक() विशिष्टता (अप्रत्याशित)
C
Try-catch inside function फ़ंक्शन के अंदर पकड़ने का प्रयास करें
D
Exception class hierarchy अपवाद वर्ग पदानुक्रम
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) noexcept specifier (C++11) declares a function doesn't throw; violations call terminate().
व्याख्या (हिन्दी) noexcept विनिर्देशक (C++11) घोषित करता है कि कोई फ़ंक्शन फेंकता नहीं है; उल्लंघन कॉल समाप्त()।
13
EN + हिं
GB What is the output: auto f=[]()noexcept{throw 1;}; try{f();}catch(...){cout<<'C';}
IN आउटपुट क्या है: auto f=[]()noexcept{throw 1;}; प्रयास करें{f();}पकड़ो(...){cout
A
C सी
B
std::terminate called std::समाप्त बुलाया गया
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) noexcept function throwing calls std::terminate, not caught by catch.
व्याख्या (हिन्दी) noexcept फ़ंक्शन थ्रोइंग कॉल std::समाप्त, कैच द्वारा नहीं पकड़ा गया।
14
EN + हिं
GB What is 'std::exception_ptr'?
IN 'std::exception_ptr' क्या है?
A
Pointer-like type that can store and rethrow exceptions पॉइंटर जैसा प्रकार जो अपवादों को संग्रहीत और पुनर्स्थापित कर सकता है
B
Base class for all exceptions सभी अपवादों के लिए बेस क्लास
C
Exception handling overhead ओवरहेड अपवाद हैंडलिंग
D
Stack pointer during exception अपवाद के दौरान स्टैक सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) std::exception_ptr enables storing and rethrowing exceptions across threads or callbacks.
व्याख्या (हिन्दी) std::exception_ptr थ्रेड या कॉलबैक में अपवादों को संग्रहीत करने और पुनर्स्थापित करने में सक्षम बनाता है।
15
EN + हिं
GB What is the output: try{int*p=nullptr; *p=1;}catch(runtime_error& e){cout<<'R';}catch(...){cout<<'A';}
IN आउटपुट क्या है: Try{int*p=nullptr; *p=1;}catch(runtime_error& e){cout
A
R आर
B
A
C
std::terminate एसटीडी::समाप्त
D
Undefined behavior (no exception) अपरिभाषित व्यवहार (कोई अपवाद नहीं)
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Dereferencing null pointer is undefined behavior; it does NOT throw a C++ exception — it likely causes a crash/signal.
व्याख्या (हिन्दी) अशक्त सूचक को संदर्भित करना अपरिभाषित व्यवहार है; यह C++ अपवाद नहीं फेंकता - यह संभावित रूप से क्रैश/सिग्नल का कारण बनता है।
1–15 of 123