OOP Using C++ — MCQ Practice

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

📚 101 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
101 questions

Question 76

EN + हिं
GB What is the output: class A{public:virtual int calc(int x)const=0;}; class SqA:public A{public:int calc(int x)const override{return x*x;}}; class CuA:public A{public:int calc(int x)const override{return x*x*x;}}; auto eval=[](const A& a,int x){return a.calc(x);}; SqA sq; CuA cu; cout<
IN आउटपुट क्या है: class A{public:virtual int calc(int x)const=0;}; वर्ग SqA:सार्वजनिक A{सार्वजनिक:int calc(int x)const ओवरराइड{रिटर्न x*x;}}; वर्ग CuA: सार्वजनिक A {सार्वजनिक: int calc (int x) स्थिरांक ओवरराइड {वापसी x*x*x;}}; ऑटो eval=[](const A& a,int x){return a.calc(x);}; वर्गA वर्ग; CuA cu; अदालत
927 927
Compile error संकलन त्रुटि
Undefined अपरिभाषित
9 27 9 27
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) sq(3)=9; cu(3)=27. Output: 927.
व्याख्या (हिन्दी) वर्ग(3)=9; घन(3)=27. आउटपुट: 927.
🎯 Exam Perspective
OOP Using C++ ("Abstraction" sub-topic) के इस प्रश्न को कई प्रतियोगी परीक्षाओं जैसे UPSC, SSC, Banking और Police भर्ती में repeat होते देखा गया है। Concept clarity के लिए explanation section जरूर पढ़ें।

Question 77

EN + हिं
GB What is the output: template T clampT(T v,T lo,T hi){return vhi?hi:v;} cout<
IN आउटपुट क्या है: टेम्पलेट टी क्लैंपटी(टी वी,टी लो,टी हाय){रिटर्न वीएचआई?हाय:वी;} कॉउट
5010 5010
1510 1510
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5: in range=5; -5: below=0; 15: above=10. Output: 5010.
व्याख्या (हिन्दी) 5: सीमा में=5; -5: नीचे=0; 15: ऊपर=10. आउटपुट: 5010.
🎯 Exam Perspective
यह सवाल OOP Using C++ ("Abstraction" sub-topic) category का है, और Railway, SSC, Banking और Defence परीक्षाओं के exam pattern में इस तरह के questions common हैं। Answer choose करने के बाद दिया गया explanation जरूर पढ़ें।

Question 78

EN + हिं
GB What is the output: class Filter{public:virtual bool pass(int x)const=0;}; class Even:public Filter{public:bool pass(int x)const override{return x%2==0;}}; class Pos:public Filter{public:bool pass(int x)const override{return x>0;}}; auto apply=[](vectorv,const Filter& f){vectorr;for(int x:v)if(f.pass(x))r.push_back(x);return r;};Even e; auto r=apply({-2,1,2,3,4},e); cout<
IN आउटपुट क्या है: वर्ग फ़िल्टर{सार्वजनिक:वर्चुअल बूल पास(int x)const=0;}; कक्षा सम:सार्वजनिक फ़िल्टर{सार्वजनिक:बूल पास(int x)const ओवरराइड{रिटर्न x%2==0;}}; वर्ग स्थिति:सार्वजनिक फ़िल्टर{सार्वजनिक:बूल पास(int x)const ओवरराइड{वापसी x>0;}}; स्वत: लागू=[](वेक्टरv,const फ़िल्टर& f){vectorr;for(int x:v)if(f.pass(x))r.push_back(x);रिटर्न r;};सम ई; स्वतः r=लागू करें({-2,1,2,3,4},e); अदालत
3 3
2 2
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Even from {-2,1,2,3,4}: -2,2,4. size=3. Output: 3.
व्याख्या (हिन्दी) {-2,1,2,3,4} से भी: -2,2,4. आकार=3. आउटपुट: 3.
🎯 Exam Perspective
यह प्रश्न OOP Using C++ ("Abstraction" sub-topic) की तैयारी करने वाले अभ्यर्थियों के लिए उपयोगी है। इस तरह के प्रश्न अक्सर SSC, Railway, Banking और State PCS जैसी परीक्षाओं में पूछे जाते रहे हैं, इसलिए concept और explanation दोनों को ध्यान से समझें, सिर्फ उत्तर याद न करें।

Question 79

EN + हिं
GB What is the output: template class Box{T v; public:Box(T x):v(x){} T get()const{return v;} Box map(functionf)const{return Box(f(v));}}; Boxb(5); cout<
IN आउटपुट क्या है: टेम्पलेट क्लास बॉक्स{T v; सार्वजनिक: बॉक्स (टी एक्स): वी (एक्स) {} टी गेट() कॉन्स्ट {रिटर्न वी;} बॉक्स मैप (फंक्शनएफ) कॉन्स्ट {रिटर्न बॉक्स (एफ (वी));}}; बॉक्सबी(5); अदालत
11 11
10 10
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10; 10+1=11. Output: 11.
व्याख्या (हिन्दी) 5*2=10; 10+1=11. आउटपुट: 11.
🎯 Exam Perspective
OOP Using C++ ("Abstraction" sub-topic) से जुड़ा यह सवाल उन students के लिए काम का है जो SSC CGL, IBPS, RRB और State-level परीक्षाओं की तैयारी कर रहे हैं। बेहतर होगा कि explanation पढ़कर concept clear करें, ताकि exam में similar प्रश्न आने पर confusion न हो।

Question 80

EN + हिं
GB What is the output: class Expr{public:virtual int eval()const=0; virtual ~Expr()=default;}; class Num:public Expr{int v;public:Num(int x):v(x){} int eval()const override{return v;}}; class Add:public Expr{Expr*l,*r;public:Add(Expr*a,Expr*b):l(a),r(b){} int eval()const override{return l->eval()+r->eval();}}; Expr*e=new Add(new Num(3),new Add(new Num(4),new Num(5))); cout<eval();
IN आउटपुट क्या है: class Expr{public:virtual int eval()const=0; आभासी ~Expr()=डिफ़ॉल्ट;}; वर्ग संख्या:सार्वजनिक व्याख्या{int v;सार्वजनिक:Num(int x):v(x){} int eval()const ओवरराइड{रिटर्न v;}}; वर्ग जोड़ें:सार्वजनिक एक्सपीआर{एक्सपीआर*एल,*आर;सार्वजनिक:जोड़ें(एक्सपीआर*ए,एक्सपीआर*बी):एल(ए),आर(बी){} int eval()const ओवरराइड{रिटर्न l->eval()+r->eval();}}; एक्सप्र*ई=नया जोड़ें(नया नंबर(3),नया जोड़ें(नया नंबर(4),नया नंबर(5))); अदालत
12 12
7 7
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+(4+5)=12. Output: 12.
व्याख्या (हिन्दी) 3+(4+5)=12. आउटपुट: 12.
🎯 Exam Perspective
UPSC, SSC, Banking और Police भर्ती जैसी परीक्षाओं में OOP Using C++ ("Abstraction" sub-topic) से सवाल अक्सर पूछे जाते हैं। इसलिए सिर्फ answer रटने के बजाय, नीचे दी गई explanation को ध्यान से पढ़ें और concept समझें।

Question 81

EN + हिं
GB What is the output: template T fold(vectorv,T init,functionf){for(T x:v)init=f(init,x);return init;} cout<({1,2,3,4,5},0,[](int a,int b){return a+b;})<({1,2,3,4,5},1,[](int a,int b){return a*b;});
IN आउटपुट क्या है: टेम्पलेट T फ़ोल्ड(वेक्टरv,T init,functionf){for(T x:v)init=f(init,x);रिटर्न init;} cout
15120 15120
Compile error संकलन त्रुटि
Undefined अपरिभाषित
15 120 15 120
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Sum=15; Product=120. Output: 15120.
व्याख्या (हिन्दी) योग=15; उत्पाद=120. आउटपुट: 15120.
🎯 Exam Perspective
अगर आप Railway, SSC, Banking और Defence परीक्षाओं की तैयारी कर रहे हैं, तो OOP Using C++ ("Abstraction" sub-topic) का यह topic आपके लिए महत्वपूर्ण है। Exam में accuracy बढ़ाने के लिए हर सवाल की explanation जरूर पढ़ें।

Question 82

EN + हिं
GB What is the output: class Predicate{public:virtual bool operator()(int x)const=0;}; class GT{int t; public:GT(int v):t(v){} bool operator()(int x)const{return x>t;}}; auto count=[](vectorv,functionp){return count_if(v.begin(),v.end(),p);}; GT g(3); cout<
IN आउटपुट क्या है: क्लास प्रेडिकेट{पब्लिक:वर्चुअल बूल ऑपरेटर()(int x)const=0;}; क्लास जीटी{इंट टी; सार्वजनिक:GT(int v):t(v){} bool ऑपरेटर()(int x)const{return x>t;}}; ऑटो काउंट=[](वेक्टरv,फंक्शनपी){रिटर्न काउंट_आईएफ(v.begin(),v.end(),p);}; जीटी जी(3); अदालत
2 2
3 3
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 4 and 5 are >3. count=2. Output: 2.
व्याख्या (हिन्दी) 4 और 5 >3 हैं। गिनती=2. आउटपुट: 2.
🎯 Exam Perspective
OOP Using C++ ("Abstraction" sub-topic) के इस प्रश्न को कई प्रतियोगी परीक्षाओं जैसे SSC, Railway, Banking और State PCS में repeat होते देखा गया है। Concept clarity के लिए explanation section जरूर पढ़ें।

Question 83

EN + हिं
GB What is the output: template vector mapV(vectorv,F f){for(T&x:v)x=f(x);return v;} auto r=mapV({1,2,3,4,5},[](int x){return x*x;}); cout<
IN आउटपुट क्या है: टेम्पलेट वेक्टर मैपV(वेक्टरv,F f){for(T&x:v)x=f(x);रिटर्न v;} ऑटो r=mapV({1,2,3,4,5},[](int x){रिटर्न x*x;}); अदालत
9 9
3 3
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r[2]=3^2=9. Output: 9.
व्याख्या (हिन्दी) आर[2]=3^2=9. आउटपुट: 9.
🎯 Exam Perspective
यह सवाल OOP Using C++ ("Abstraction" sub-topic) category का है, और SSC CGL, IBPS, RRB और State-level परीक्षाओं के exam pattern में इस तरह के questions common हैं। Answer choose करने के बाद दिया गया explanation जरूर पढ़ें।

Question 84

EN + हिं
GB What is the output: class Transform{public:virtual int apply(int x)const=0; virtual ~Transform()=default;}; class Scale:public Transform{int f;public:Scale(int v):f(v){} int apply(int x)const override{return x*f;}}; class Shift:public Transform{int s;public:Shift(int v):s(v){} int apply(int x)const override{return x+s;}}; vectorts={new Scale(2),new Shift(3)}; int v=5; for(auto t:ts)v=t->apply(v); cout<
IN आउटपुट क्या है: class Transform{public:virtual int apply(int x)const=0; आभासी ~परिवर्तन()=डिफ़ॉल्ट;}; वर्ग स्केल:सार्वजनिक ट्रांसफ़ॉर्म{int f;सार्वजनिक:स्केल(int v):f(v){} int apply(int x)const ओवरराइड{रिटर्न x*f;}}; क्लास शिफ्ट:पब्लिक ट्रांसफॉर्म{int s;public:Shift(int v):s(v){} int apply(int x)const ओवरराइड{रिटर्न x+s;}}; वेक्टरट्स={नया स्केल(2),नया शिफ्ट(3)}; int v=5; for(auto t:ts)v=t->apply(v); अदालत
13 13
10 10
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10; 10+3=13. Output: 13.
व्याख्या (हिन्दी) 5*2=10; 10+3=13. आउटपुट: 13.
🎯 Exam Perspective
यह प्रश्न OOP Using C++ ("Abstraction" sub-topic) की तैयारी करने वाले अभ्यर्थियों के लिए उपयोगी है। इस तरह के प्रश्न अक्सर UPSC, SSC, Banking और Police भर्ती जैसी परीक्षाओं में पूछे जाते रहे हैं, इसलिए concept और explanation दोनों को ध्यान से समझें, सिर्फ उत्तर याद न करें।

Question 85

EN + हिं
GB What is the output: template class Optional{bool has;T v;public:Optional():has(false){} Optional(T x):has(true),v(x){} bool hasValue()const{return has;} T value()const{return v;} T valueOr(T d)const{return has?v:d;}}; Optionala(5),b; cout<
IN आउटपुट क्या है: टेम्पलेट वर्ग वैकल्पिक {बूल है; टी वी; सार्वजनिक: वैकल्पिक(): है (झूठा) {} वैकल्पिक (टी एक्स): है (सत्य), वी (एक्स) {} बूल है वैल्यू() कॉन्स्ट {रिटर्न है;} टी वैल्यू() कॉन्स्ट {रिटर्न वी;} टी वैल्यूऑर (टी डी) कॉन्स्ट {रिटर्न है? वी: डी;}}; वैकल्पिक(5),बी; अदालत
599 599
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=5, b=empty=99. Output: 599.
व्याख्या (हिन्दी) ए=5, बी=खाली=99। आउटपुट: 599.
🎯 Exam Perspective
OOP Using C++ ("Abstraction" sub-topic) से जुड़ा यह सवाल उन students के लिए काम का है जो Railway, SSC, Banking और Defence परीक्षाओं की तैयारी कर रहे हैं। बेहतर होगा कि explanation पढ़कर concept clear करें, ताकि exam में similar प्रश्न आने पर confusion न हो।

Question 86

EN + हिं
GB What is the output: class Visitor{public:virtual void visitInt(int x)=0; virtual void visitStr(const string& s)=0;}; class Print:public Visitor{public:void visitInt(int x)override{cout<
IN आउटपुट क्या है: वर्ग विज़िटर{सार्वजनिक:वर्चुअल शून्य विज़िटइंट(int x)=0; आभासी शून्य विज़िटStr(const string& s)=0;}; वर्ग प्रिंट:सार्वजनिक विज़िटर{सार्वजनिक:शून्य विज़िटइंट(int x)ओवरराइड{काउट
42hi 42हि
Compile error संकलन त्रुटि
Undefined अपरिभाषित
hi42 हाय42
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 42 then hi. Output: 42hi.
व्याख्या (हिन्दी) 42 फिर हाय. आउटपुट: 42हाय.
🎯 Exam Perspective
SSC, Railway, Banking और State PCS जैसी परीक्षाओं में OOP Using C++ ("Abstraction" sub-topic) से सवाल अक्सर पूछे जाते हैं। इसलिए सिर्फ answer रटने के बजाय, नीचे दी गई explanation को ध्यान से पढ़ें और concept समझें।

Question 87

EN + हिं
GB What is the output: template struct IsPrime{static const bool v=[](){for(int i=2;i*i<=N;i++)if(N%i==0)return false;return N>1;}();}; cout<::v<::v;
IN आउटपुट क्या है: टेम्पलेट स्ट्रक्चर IsPrime{static const bool v=[](){for(int i=2;i*i1;}();}; cout
10 10
11 11
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 7 prime=1; 9=3*3 not prime=0. Output: 10.
व्याख्या (हिन्दी) 7 अभाज्य=1; 9=3*3 अभाज्य=0 नहीं। आउटपुट: 10.
🎯 Exam Perspective
अगर आप SSC CGL, IBPS, RRB और State-level परीक्षाओं की तैयारी कर रहे हैं, तो OOP Using C++ ("Abstraction" sub-topic) का यह topic आपके लिए महत्वपूर्ण है। Exam में accuracy बढ़ाने के लिए हर सवाल की explanation जरूर पढ़ें।

Question 88

EN + हिं
GB What is the output: class A{public:virtual string repr()const=0;}; class Int:public A{int v;public:Int(int x):v(x){} string repr()const override{return to_string(v);}}; class Str:public A{string s;public:Str(string t):s(t){} string repr()const override{return '"'+s+'"';}}; vectorv={new Int(42),new Str("hi")}; for(auto p:v)cout<repr()<<' ';
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल स्ट्रिंग रिप्र()कॉन्स्ट=0;}; क्लास इंट:पब्लिक ए{इंट वी;पब्लिक:इंट(इंट एक्स):वी(एक्स){} स्ट्रिंग रिप्र()कॉन्स्ट ओवरराइड{रिटर्न टू_स्ट्रिंग(वी);}}; क्लास स्ट्र:पब्लिक ए{स्ट्रिंग एस;पब्लिक:स्ट्र(स्ट्रिंग टी):एस(टी){} स्ट्रिंग रिप्र()कॉन्स्ट ओवरराइड{रिटर्न '''+एस+''';}}; वेक्टरv={नया इंट(42),नया स्ट्र('हाय')}; for(auto p:v)cout
42 "hi" 42 "हाय"
Compile error संकलन त्रुटि
Undefined अपरिभाषित
42hi 42हि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 42 and "hi". Output: 42 "hi".
व्याख्या (हिन्दी) 42 और "हाय"। आउटपुट: 42 "हाय"।
🎯 Exam Perspective
OOP Using C++ ("Abstraction" sub-topic) के इस प्रश्न को कई प्रतियोगी परीक्षाओं जैसे UPSC, SSC, Banking और Police भर्ती में repeat होते देखा गया है। Concept clarity के लिए explanation section जरूर पढ़ें।

Question 89

EN + हिं
GB What is the output: template T identity_(T x){return x;} template T applyFn(F f,T x){return f(x);} cout<,5);
IN आउटपुट क्या है: टेम्प्लेट T पहचान_(T x){रिटर्न x;} टेम्प्लेट T अप्लाईFn(F f,T x){रिटर्न f(x);} कॉउट
5 5
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) identity_(5)=5. Output: 5.
व्याख्या (हिन्दी) पहचान_(5)=5. आउटपुट: 5.
🎯 Exam Perspective
यह सवाल OOP Using C++ ("Abstraction" sub-topic) category का है, और Railway, SSC, Banking और Defence परीक्षाओं के exam pattern में इस तरह के questions common हैं। Answer choose करने के बाद दिया गया explanation जरूर पढ़ें।

Question 90

EN + हिं
GB What is the output: class Lens{int A::*ptr; public:Lens(int A::*p):ptr(p){} int get(const A& a)const{return a.*ptr;} void set(A& a,int v)const{a.*ptr=v;}}; struct A{int x=0,y=0;}; Lens lx(&A::x); A a; lx.set(a,5); cout<
IN आउटपुट क्या है: क्लास लेंस{int A::*ptr; सार्वजनिक:लेंस(int A::*p):ptr(p){} int get(const A& a)const{return a.*ptr;} void set(A& a,int v)const{a.*ptr=v;}}; संरचना A{int x=0,y=0;}; लेंस lx(&A::x); ए ए; एलएक्स.सेट(ए,5); अदालत
5 5
Compile error संकलन त्रुटि
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) lx.set sets a.x=5; lx.get returns 5. Output: 5.
व्याख्या (हिन्दी) lx.set सेट a.x=5; lx.get रिटर्न 5. आउटपुट: 5.
🎯 Exam Perspective
यह प्रश्न OOP Using C++ ("Abstraction" sub-topic) की तैयारी करने वाले अभ्यर्थियों के लिए उपयोगी है। इस तरह के प्रश्न अक्सर SSC, Railway, Banking और State PCS जैसी परीक्षाओं में पूछे जाते रहे हैं, इसलिए concept और explanation दोनों को ध्यान से समझें, सिर्फ उत्तर याद न करें।