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
1846
EN + हिं
GB What is the output: class I{public:virtual void exec()=0; virtual ~I()=default;}; class Greet:public I{string n;public:Greet(string s):n(s){} void exec()override{cout<<"Hi "+n;}}; queue>q; q.push(make_unique("A")); q.push(make_unique("B")); while(!q.empty()){q.front()->exec();q.pop();}
IN आउटपुट क्या है: क्लास I{public:virtual void exec()=0; आभासी ~I()=डिफ़ॉल्ट;}; क्लास ग्रीट:पब्लिक I{स्ट्रिंग n;पब्लिक:ग्रीट(स्ट्रिंग s):n(s){} void exec()ओवरराइड{cout
A
Hi AHi B हाय एहाय बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Hi A Hi B हाय ए हाय बी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) FIFO: Hi A then Hi B. Output: Hi AHi B.
व्याख्या (हिन्दी) फीफो: हाय ए, फिर हाय बी। आउटपुट: हाय ए, हाय बी।
1847
EN + हिं
GB What is the output: template class Lazy2{mutable optionalcache; functionfn; public:Lazy2(functionf):fn(f){} T get()const{if(!cache)cache=fn();return *cache;}}; int c=0; Lazy2l([&c](){return ++c;}); cout<
IN आउटपुट क्या है: टेम्पलेट क्लास Lazy2{म्यूटेबल ऑप्शनल कैश; functionfn; सार्वजनिक:Lazy2(functionf):fn(f){} T get()const{if(!cache)cache=fn();return *cache;}}; पूर्णांक सी=0; Lazy2l([&c](){रिटर्न++c;}); अदालत
A
111 111
B
121 121
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) First get(): c=1,cache=1. Second: from cache=1. c=1. Output: 111.
व्याख्या (हिन्दी) सबसे पहले प्राप्त करें(): c=1,cache=1. दूसरा: कैश से=1. सी=1. आउटपुट: 111.
1848
EN + हिं
GB What is the output: template auto transform_pair(pairp,functionf,functiong){return make_pair(f(p.first),g(p.second));} auto r=transform_pair({5,"hi"},[](int x){return x*2;},[](string s){return s+"!";}); cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो ट्रांसफॉर्म_पेयर(पेयरप,फंक्शनएफ,फंक्शनजी){रिटर्न मेक_पेयर(एफ(पी.फर्स्ट),जी(पी.सेकेंड));} ऑटो आर=ट्रांसफॉर्म_पेयर({5,"हाय"},[](इंट एक्स){रिटर्न x*2;},[](स्ट्रिंग एस){रिटर्न एस+"!";}); अदालत
A
10hi! 10हाय!
B
5hi 5हाय
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10; "hi"+"!"="hi!". Output: 10hi!.
व्याख्या (हिन्दी) 5*2=10; "हाय"+"!"="हाय!"। आउटपुट: 10हाय!
1849
EN + हिं
GB What is the output: try{int x=5,y=0;if(!y)throw domain_error("div0");cout<
IN आउटपुट क्या है: Try{int x=5,y=0;if(!y)throw Domain_error("div0");cout
A
div0 div0
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Throws domain_error. Output: div0.
व्याख्या (हिन्दी) डोमेन_त्रुटि फेंकता है। आउटपुट: div0.
1850
EN + हिं
GB What is the output: try{vectorv={1,2,3};cout<
IN आउटपुट क्या है: Try{vectorv={1,2,3};cout
A
O हे
B
E
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) at(5) on size-3 vector: out_of_range. Output: O.
व्याख्या (हिन्दी) at(5) आकार-3 वेक्टर पर: out_of_range। आउटपुट: ओ.
1851
EN + हिं
GB What is the output: struct A{~A()noexcept{cout<<'D';}}; try{A a;throw 1;}catch(int){cout<<'C';}
IN आउटपुट क्या है: struct A{~A()noexcept{cout
A
DC डीसी
B
CD सीडी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Stack unwind: ~A=D; catch: C. Output: DC.
व्याख्या (हिन्दी) स्टैक अनवाइंड: ~ए=डी; कैच: सी. आउटपुट: डीसी.
1852
EN + हिं
GB What is the output: int f()noexcept{return 42;} try{cout<
IN आउटपुट क्या है: int f()noexcept{return 42;} Try{cout
A
42 42
B
X एक्स
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() returns 42, no throw. Output: 42.
व्याख्या (हिन्दी) f() 42 लौटाता है, कोई थ्रो नहीं। आउटपुट: 42.
1853
EN + हिं
GB What is the output: auto safe=[](auto f,auto... args)->optional{try{return f(args...);}catch(...){return nullopt;}}; auto r=safe([](int x,int y)->int{if(!y)throw 1;return x/y;},10,0); cout<
IN आउटपुट क्या है: ऑटो सेफ=[](ऑटो एफ,ऑटो...आर्ग्स)->वैकल्पिक{प्रयास{रिटर्न एफ(आर्ग्स...);}कैच(...){रिटर्न नॉलॉप्ट;}}; ऑटो आर=सुरक्षित([](int x,int y)->int{if(!y)throw 1;return x/y;},10,0); अदालत
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Throws; returns nullopt. has_value=0. Output: 0.
व्याख्या (हिन्दी) फेंकता है; शून्य लौटाता है। has_value=0. आउटपुट: 0.
1854
EN + हिं
GB What is the output: try{string s=string(1,'A'); s.at(5);}catch(out_of_range&){cout<<'O';}
IN आउटपुट क्या है: Try{string s=string(1,'A'); s.at(5);}कैच(out_of_range&){cout
A
O हे
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) s.at(5) on size-1 string: out_of_range. Output: O.
व्याख्या (हिन्दी) s.at(5) आकार-1 स्ट्रिंग पर: out_of_range। आउटपुट: ओ.
1855
EN + हिं
GB What is the output: int n=0; try{for(int i=0;i<5;i++){n++;if(n==3)throw n;}}catch(int x){cout<
IN आउटपुट क्या है: int n=0; प्रयास करें{for(int i=0;i
A
33 33
B
35 35
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Throws when n==3. x=3,n=3. Output: 33.
व्याख्या (हिन्दी) फेंकता है जब n==3. एक्स=3,एन=3. आउटपुट: 33.
1856
EN + हिं
GB What is the output: class E:public runtime_error{public:E(string s):runtime_error(s){}}; try{throw E("myerr");}catch(E& e){cout<
IN आउटपुट क्या है: क्लास ई:पब्लिक रनटाइम_एरर{पब्लिक:ई(स्ट्रिंग एस):रनटाइम_एरर(एस){}}; प्रयास करें{फेंकें E("myerr");}पकड़ें(E& e){cout
A
myerr मायर
B
E
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) e.what()=myerr. Output: myerr.
व्याख्या (हिन्दी) e.what()=myerr. आउटपुट: मायर.
1857
EN + हिं
GB What is the output: int x=0; try{x=1;try{x=2;throw 1;x=3;}catch(int){x=4;}} cout<
IN आउटपुट क्या है: int x=0; प्रयास करें {x = 1; प्रयास करें {x = 2; फेंकें 1;
A
4 4
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=1,2; throw; x=4. Output: 4.
व्याख्या (हिन्दी) एक्स=1,2; फेंक; एक्स=4. आउटपुट: 4.
1858
EN + हिं
GB What is the output: void f(){try{throw 1;}catch(int i){cout<
IN आउटपुट क्या है: void f(){try{throw 1;}catch(int i){cout
A
111 111
B
1 11 1 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f: catch prints 1, throws 11. Outer: catches 11. Output: 111.
व्याख्या (हिन्दी) एफ: कैच प्रिंट 1, थ्रो 11. आउटर: कैच 11. आउटपुट: 111.
1859
EN + हिं
GB What is the output: try{auto p=make_unique(5); throw *p;}catch(int i){cout<
IN आउटपुट क्या है: Try{auto p=make_unique(5); फेंको *p;}पकड़ो(int i){cout
A
5 5
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) throw *p throws int 5. Output: 5.
व्याख्या (हिन्दी) थ्रो *पी थ्रो इंट 5. आउटपुट: 5.
1860
EN + हिं
GB What is the output: struct Guard{int& r; Guard(int& x):r(x){r=1;} ~Guard(){r=2;}}; int x=0; try{Guard g(x); throw 1;}catch(int){cout<
IN आउटपुट क्या है: structguard{int& r; गार्ड(int& x):r(x){r=1;} ~गार्ड(){r=2;}}; int x=0; कोशिश करें {गार्ड जी (एक्स); फेंको 1;}पकड़ो(int){cout
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ~Guard: r=2. catch: cout<
व्याख्या (हिन्दी) ~गार्ड: r=2. पकड़ो: कोउट
1846–1860 of 1915