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
76
EN + हिं
GB What is the output: try{string s=string(size_t(-1),'x');}catch(bad_alloc&){cout<<'M';}catch(length_error&){cout<<'L';}
IN आउटपुट क्या है: Try{string s=string(size_t(-1),'x');}catch( Bad_alloc&){cout
A
L एल
B
M एम
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) size_t(-1) is UINT_MAX — too large; string throws length_error or bad_alloc. Most likely bad_alloc. Output: M.
व्याख्या (हिन्दी) size_t(-1) UINT_MAX है - बहुत बड़ा; स्ट्रिंग length_error या Bad_alloc फेंकती है। सबसे अधिक संभावना ख़राब_आवंटन। आउटपुट: एम.
77
EN + हिं
GB What is the output: try{stod("3.14");}catch(invalid_argument&){cout<<'I';}catch(...){cout<<'X';} cout<
IN आउटपुट क्या है: प्रयास करें {stod ("3.14");} पकड़ें (अमान्य_argument &) {cout
A
3.14 3.14
B
I मैं
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) stod("3.14") succeeds; no catch. cout outputs 3.14. Output: 3.14.
व्याख्या (हिन्दी) Stod('3.14') सफल होता है; कोई पकड़ नहीं. कॉउट आउटपुट 3.14. आउटपुट: 3.14.
78
EN + हिं
GB What is the output: auto safe_div=[](int a,int b)->optional{if(b==0) return nullopt; return a/b;}; auto r=safe_div(10,3); cout<<(r?*r:-1);
IN आउटपुट क्या है: autosafe_div=[](int a,int b)-> वैकल्पिक{if(b==0) return nullopt; वापसी ए/बी;}; ऑटो r=safe_div(10,3); अदालत
A
3 3
B
-1 -1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b!=0: r=10/3=3. Output: 3.
व्याख्या (हिन्दी) बी!=0: आर=10/3=3. आउटपुट: 3.
79
EN + हिं
GB What is the output: try{throw 1;}catch(int i){cout<
IN आउटपुट क्या है: Try{throw 1;}catch(int i){cout
A
121 121
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Outer catches 1 (prints 1); inner throws 2, catches (prints 2); then prints i=1 again. Output: 121.
व्याख्या (हिन्दी) बाहरी कैच 1 (प्रिंट 1); आंतरिक थ्रो 2, कैच (प्रिंट 2); फिर i=1 फिर से प्रिंट करता है। आउटपुट: 121.
80
EN + हिं
GB What is the output: class Ex{int c; public:Ex(int v):c(v){} int code()const{return c;}}; try{throw Ex(42);}catch(Ex& e){cout<
IN आउटपुट क्या है: class Ex{int c; सार्वजनिक:Ex(int ​​v):c(v){} int कोड()const{return c;}}; प्रयास करें{फेंकें Ex(42);}पकड़ें(Ex& e){cout
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) e.code()=42. Output: 42.
व्याख्या (हिन्दी) ई.कोड()=42. आउटपुट: 42.
81
EN + हिं
GB What is the output: int x=0; try{x=1;if(x) throw 'E';x=2;}catch(char c){cout<
IN आउटपुट क्या है: int x=0; प्रयास करें{x=1;if(x) फेंक 'ई';x=2;}पकड़ें(char c){cout
A
E1 ई 1
B
E2 ई2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=1; throw 'E'; x=2 skipped; catch prints E; cout<
व्याख्या (हिन्दी) एक्स=1; 'ई' फेंको; x=2 छोड़ दिया गया; कैच प्रिंट ई; अदालत
82
EN + हिं
GB What is the output: struct RAII{int& r;RAII(int& x):r(x){r=1;} ~RAII(){r=0;}}; int x=0; try{RAII g(x); throw 1;}catch(int){cout<
IN आउटपुट क्या है: struct RAII{int& r;RAII(int& x):r(x){r=1;} ~RAII(){r=0;}}; int x=0; प्रयास करें{RAII g(x); फेंको 1;}पकड़ो(int){cout
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Stack unwind: ~RAII sets x=0. catch: cout<
व्याख्या (हिन्दी) स्टैक अनवाइंड: ~RAII x=0 सेट करता है। पकड़ो: कोउट
83
EN + हिं
GB What is the output: try{try{throw runtime_error("err");}catch(logic_error&){cout<<'L';}}catch(runtime_error&e){cout<
IN आउटपुट क्या है: प्रयास करें {कोशिश करें {थ्रो रनटाइम_एरर ("इर्रर");}कैच (लॉजिक_एरर और) {काउट
A
err ग़लती होना
B
L एल
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inner doesn't match; propagates to outer: err. Output: err.
व्याख्या (हिन्दी) भीतरी मेल नहीं खाता; बाहरी तक फैलता है: err. आउटपुट: ग़लती।
84
EN + हिं
GB What is the output: auto f=[]()->expected{return 42;}; auto g=[]()->expected{return unexpected("fail");}; cout<
IN आउटपुट क्या है: auto f=[]()->expected{return 42;}; ऑटो g=[]()->अपेक्षित{वापसी अप्रत्याशित('असफल');}; अदालत
A
420 420
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
42 0 42 0
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f()=42; g() has no value. Output: 420.
व्याख्या (हिन्दी) एफ()=42; g() का कोई मूल्य नहीं है। आउटपुट: 420.
85
EN + हिं
GB What is the output: int n=0; try{for(int i=0;i<5;i++){n++; if(i==2) throw i;}}catch(int i){cout<
IN आउटपुट क्या है: int n=0; प्रयास करें{for(int i=0;i
A
33 33
B
32 32
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) i=0:n=1;i=1:n=2;i=2:n=3,throw 2. catch: cout<<3<<2. Output: 32.
व्याख्या (हिन्दी) i=0:n=1;i=1:n=2;i=2:n=3,थ्रो 2. कैच: कॉउट
86
EN + हिं
GB What is the output: class A{public:~A()noexcept(false){throw 1;}}; try{A a;}catch(...){cout<<'X';}
IN आउटपुट क्या है: वर्ग A{सार्वजनिक:~A()noexcept(false){throw 1;}}; प्रयास करें{ए ए;}पकड़ो(...){कोउट
A
X एक्स
B
std::terminate एसटीडी::समाप्त
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Destructor throws; no active exception: std::terminate called. Output: terminate.
व्याख्या (हिन्दी) विध्वंसक फेंकता है; कोई सक्रिय अपवाद नहीं: std::terminet कहा गया। आउटपुट: समाप्त करें.
87
EN + हिं
GB What is the output: void f()noexcept{cout<<1;} void g(){try{f();}catch(...){cout<<2;}} g();
IN आउटपुट क्या है: void f()noexcept{cout
A
1 1
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() doesn't throw; catch not entered. Output: 1.
व्याख्या (हिन्दी) f() फेंकता नहीं है; कैच दर्ज नहीं किया गया. आउटपुट: 1.
88
EN + हिं
GB What is the output: try{int x=stoi("2147483648");}catch(out_of_range&){cout<<'O';}
IN आउटपुट क्या है: Try{int x=stoi('2147483648');}catch(out_of_range&){cout
A
O हे
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
2147483648 2147483648
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 2147483648 > INT_MAX: stoi throws out_of_range. Output: O.
व्याख्या (हिन्दी) 2147483648 > INT_MAX: Stoi आउट_ऑफ़_रेंज फेंकता है। आउटपुट: ओ.
89
EN + हिं
GB What is the output: try{throw 1;}catch(int i){cout<
IN आउटपुट क्या है: Try{throw 1;}catch(int i){cout
A
1 1
B
12 12
C
std::terminate एसटीडी::समाप्त
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) throw i+1 propagates outside the try-catch; no outer handler: terminate. Output: 1 then terminate.
व्याख्या (हिन्दी) थ्रो i+1 ट्राई-कैच के बाहर प्रचारित होता है; कोई बाहरी हैंडलर नहीं: समाप्त करें। आउटपुट: 1 फिर समाप्त करें।
90
EN + हिं
GB What is the output: auto ex=make_exception_ptr(runtime_error("err")); try{rethrow_exception(ex);}catch(runtime_error& e){cout<
IN आउटपुट क्या है: auto ex=make_exception_ptr(runtime_error("err")); प्रयास करें{rethrow_exception(ex);}catch(runtime_error& e){cout
A
err ग़लती होना
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) rethrow_exception throws stored exception. Caught: err. Output: err.
व्याख्या (हिन्दी) rethrow_exception संग्रहीत अपवाद को फेंकता है। पकड़ा गया: ग़लती. आउटपुट: ग़लती।
76–90 of 123