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
1396
EN + हिं
GB What is the output: class Matrix{int d[2][2]={{1,2},{3,4}}; public: int& at(int i,int j){return d[i][j];} int get(int i,int j)const{return d[i][j];}}; Matrix m; m.at(0,1)=10; cout<
IN आउटपुट क्या है: क्लास मैट्रिक्स{int d[2][2]={{1,2},{3,4}}; सार्वजनिक: int& at(int i,int j){return d[i][j];} int get(int i,int j)const{return d[i][j];}}; मैट्रिक्स एम; m.at(0,1)=10; अदालत
A
10 10
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) at(0,1) returns ref to d[0][1]=2; set to 10. get(0,1)=10. Output: 10.
व्याख्या (हिन्दी) at(0,1) रेफरी को d[0][1]=2 पर लौटाता है; 10 पर सेट करें। प्राप्त करें(0,1)=10। आउटपुट: 10.
1397
EN + हिं
GB What is the output: class A{string s; public: A(string t):s(t){} string get()const{return s;} A operator+(const A& o)const{return A(s+o.s);}}; A a("hi"),b("there"); cout<<(a+b).get();
IN आउटपुट क्या है: क्लास ए{स्ट्रिंग एस; सार्वजनिक: A(string t):s(t){} string get()const{return s;} A ऑपरेटर+(const A& o)const{return A(s+o.s);}}; ए ए("हाय"),बी("वहाँ"); अदालत
A
hithere नमस्ते
B
hi नमस्ते
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) "hi"+"there"="hithere". Output: hithere.
व्याख्या (हिन्दी) "हाय"+"वहां"="यहां"। आउटपुट: यहाँ.
1398
EN + हिं
GB What is the output: class A{int x=0; public: void inc(){x++;} int get()const{return x;} A operator+(const A& o)const{A r; r.x=x+o.x; return r;}}; A a,b; a.inc();a.inc(); b.inc(); cout<<(a+b).get();
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void inc(){x++;} int get()const{return x;} A ऑपरेटर+(const A& o)const{A r; r.x=x+o.x; वापसी आर;}}; ए ए, बी; a.inc();a.inc(); b.inc(); अदालत
A
3 3
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=2, b.x=1. (a+b).x=3. Output: 3.
व्याख्या (हिन्दी) a.x=2, b.x=1. (ए+बी).एक्स=3. आउटपुट: 3.
1399
EN + हिं
GB What is the output: class A{public:virtual int f()const=0;}; class B:public A{int x; public:B(int v):x(v){} int f()const override{return x;}}; auto sum=[](vector& v){int s=0;for(auto p:v)s+=p->f();return s;}; vectorv={new B(1),new B(2),new B(3)}; cout<
IN आउटपुट क्या है: class A{public:virtual int f()const=0;}; कक्षा बी:सार्वजनिक ए{int x; सार्वजनिक:बी(int v):x(v){} int f()const ओवरराइड{रिटर्न x;}}; auto sum=[](vector& v){int s=0;for(auto p:v)s+=p->f();return s;}; वेक्टरv={नया बी(1),नया बी(2),नया बी(3)}; अदालत
A
6 6
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+3=6. Output: 6.
व्याख्या (हिन्दी) 1+2+3=6. आउटपुट: 6.
1400
EN + हिं
GB What is the output: template class Functor{T v; public:Functor(T x):v(x){} T operator()(T x){return v*x;}}; Functor f(3); cout<
IN आउटपुट क्या है: टेम्प्लेट क्लास फ़ंक्टर {T v; सार्वजनिक:फ़ंक्टर(T x):v(x){} T ऑपरेटर()(T x){रिटर्न v*x;}}; फ़ंक्टर f(3); अदालत
A
1521 1521
B
35 35
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f(5)=15; f(7)=21. Output: 1521.
व्याख्या (हिन्दी) एफ(5)=15; एफ(7)=21. आउटपुट: 1521.
1401
EN + हिं
GB What is the output: class A{public:virtual int area()const=0;}; class R:public A{int w,h;public:R(int a,int b):w(a),h(b){} int area()const{return w*h;}}; class C:public A{int r;public:C(int v):r(v){} int area()const{return r*r*3;}}; A*s[]={new R(3,4),new C(5)}; cout<area()<area();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एरिया()कॉन्स्ट=0;}; वर्ग आर:सार्वजनिक ए{int w,h;सार्वजनिक:R(int a,int b):w(a),h(b){} int क्षेत्र()const{रिटर्न w*h;}}; क्लास सी:पब्लिक ए{इंट आर;पब्लिक:सी(इंट वी):आर(वी){} इंट एरिया()कॉन्स्ट{रिटर्न आर*आर*3;}}; ए*एस[]={नया आर(3,4),नया सी(5)}; अदालत
A
1275 1275
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
12 75 12 75
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) R(3,4)=12; C(5)=75. Output: 1275.
व्याख्या (हिन्दी) आर(3,4)=12; सी(5)=75. आउटपुट: 1275.
1402
EN + हिं
GB What is the output: auto memoize=[](auto f){map cache;return [=](auto self,int n)mutable->int{if(cache.count(n))return cache[n];return cache[n]=f(self,n);};};
IN आउटपुट क्या है: ऑटो मेमोइज़=[](ऑटो एफ){मैप कैश;रिटर्न [=](ऑटो सेल्फ,इंट एन)म्यूटेबल->इंट{इफ(कैश.काउंट(एन))रिटर्न कैश[एन];रिटर्न कैश[एन]=एफ(सेल्फ,एन);};};
A
Compile error संकलन त्रुटि
B
Works काम करता है
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Complex usage — likely compile error without proper self-application. Compile error.
व्याख्या (हिन्दी) जटिल उपयोग - उचित स्व-अनुप्रयोग के बिना संभावित संकलन त्रुटि। संकलन त्रुटि.
1403
EN + हिं
GB What is the output: class Interface{public:virtual void exec()const=0; virtual ~Interface()=default;}; class Impl:public Interface{int v; public:Impl(int x):v(x){} void exec()const override{cout< p=make_shared(5); p->exec();
IN आउटपुट क्या है: वर्ग इंटरफ़ेस{सार्वजनिक:वर्चुअल शून्य निष्पादन()const=0; आभासी ~इंटरफ़ेस()=डिफ़ॉल्ट;}; वर्ग कार्यान्वयन:सार्वजनिक इंटरफ़ेस{int v; सार्वजनिक: Impl(int x):v(x){} void exec()const ओवरराइड{cout
A
25 25
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Impl::exec()=5*5=25. Output: 25.
व्याख्या (हिन्दी) कार्यान्वयन::exec()=5*5=25। आउटपुट: 25.
1404
EN + हिं
GB What is the output: template auto makeAdder(T n){return [n](T x){return x+n;};}; auto add5=makeAdder(5); cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो मेकएडर (T n) {रिटर्न [n] (T x) {रिटर्न x + n;};}; ऑटो ऐड5=मेकएडर(5); अदालत
A
815 815
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
8 15 8 15
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) add5(3)=8; add5(10)=15. Output: 815.
व्याख्या (हिन्दी) add5(3)=8; जोड़ें5(10)=15. आउटपुट: 815.
1405
EN + हिं
GB What is the output: class Abstract{public:virtual int calc(int)const=0;}; class Double:public Abstract{public:int calc(int x)const override{return x*2;}}; class Triple:public Abstract{public:int calc(int x)const override{return x*3;}}; auto apply=[](Abstract*a,int x){return a->calc(x);}; cout<
IN आउटपुट क्या है: class Abstract{public:virtual int calc(int)const=0;}; वर्ग डबल:सार्वजनिक सार{सार्वजनिक:int calc(int x)const ओवरराइड{रिटर्न x*2;}}; वर्ग ट्रिपल:सार्वजनिक सार{सार्वजनिक:int calc(int x)const ओवरराइड{रिटर्न x*3;}}; स्वतः लागू=[](सार*a,int x){वापसी a->calc(x);}; अदालत
A
1015 1015
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
10 15 10 15
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Double(5)=10; Triple(5)=15. Output: 1015.
व्याख्या (हिन्दी) दोगुना(5)=10; तिगुना(5)=15. आउटपुट: 1015.
1406
EN + हिं
GB What is the output: class EventBus{map>> handlers; public: void on(string e,functionf){handlers[e].push_back(f);} void emit(string e){for(auto&f:handlers[e])f();}}; EventBus bus; int x=0; bus.on("inc",[&]{x++;}); bus.on("inc",[&]{x+=2;}); bus.emit("inc"); cout<
IN आउटपुट क्या है: क्लास इवेंटबस{मैप हैंडलर; सार्वजनिक: void on(string e,functionf){handlers[e].push_back(f);} void emotional(string e){for(auto&f:handlers[e])f();}}; इवेंटबस बस; int x=0; Bus.on('inc',[&]{x++;}); बस.पर('inc',[&]{x+=2;}); बस.एमिट('inc'); अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both handlers fire: x+=1+2=3. Output: 3.
व्याख्या (हिन्दी) दोनों हैंडलर फायर करते हैं: x+=1+2=3. आउटपुट: 3.
1407
EN + हिं
GB What is the output: template T foldRight(vectorv,T init,F f){for(int i=v.size()-1;i>=0;i (1, 6, 83, 13, 4, 'What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; auto clone=[](A*p)->A*{return new B(*dynamic_cast(p));}; auto p=new B; auto q=clone(p); q->f();
IN आउटपुट क्या है: टेम्पलेट T फोल्डराइट(वेक्टरv,T init,F f){for(int i=v.size()-1;i>=0;i (1, 6, 83, 13, 4, 'आउटपुट क्या है: वर्ग ए {सार्वजनिक: वर्चुअल शून्य एफ() = 0;}; वर्ग बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउटफ();
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) q is new B. q->f()=B. Output: B.
व्याख्या (हिन्दी) q नया B है। q->f()=B. आउटपुट: बी.
1408
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; auto clone=[](A*p)->A*{return new B(*dynamic_cast(p));}; auto p=new B; auto q=clone(p); q->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:शून्य एफ()ओवरराइड{काउटफ();
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) q is new B. q->f()=B. Output: B.
व्याख्या (हिन्दी) q नया B है। q->f()=B. आउटपुट: बी.
1409
EN + हिं
GB What is the output: class Lazy{mutable optional cache; functionfn; public:Lazy(functionf):fn(f){} int get()const{if(!cache) cache=fn(); return *cache;}}; Lazy l([]()->int{cout<<'C';return 42;}); cout<
IN आउटपुट क्या है: क्लास आलसी {म्यूटेबल वैकल्पिक कैश; functionfn; सार्वजनिक:आलसी(फ़ंक्शनf):fn(f){} int get()const{if(!cache) कैश=fn(); वापसी *कैश;}}; आलसी l([]()->int{cout
A
C4242 सी4242
B
4242 4242
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) First get(): compute=C, cache=42. Second get(): from cache=42. Output: C4242.
व्याख्या (हिन्दी) सबसे पहले प्राप्त करें(): कंप्यूट=सी, कैश=42। दूसरा प्राप्त करें (): कैश से = 42। आउटपुट: C4242.
1410
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 फेंकती है। सबसे अधिक संभावना ख़राब_आवंटन। आउटपुट: एम.
1396–1410 of 1915