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
1831
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); अदालत
A
13 13
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10; 10+3=13. Output: 13.
व्याख्या (हिन्दी) 5*2=10; 10+3=13. आउटपुट: 13.
1832
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),बी; अदालत
A
599 599
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=5, b=empty=99. Output: 599.
व्याख्या (हिन्दी) ए=5, बी=खाली=99। आउटपुट: 599.
1833
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)ओवरराइड{काउट
A
42hi 42हि
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
hi42 हाय42
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 42 then hi. Output: 42hi.
व्याख्या (हिन्दी) 42 फिर हाय. आउटपुट: 42हाय.
1834
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
A
10 10
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 7 prime=1; 9=3*3 not prime=0. Output: 10.
व्याख्या (हिन्दी) 7 अभाज्य=1; 9=3*3 अभाज्य=0 नहीं। आउटपुट: 10.
1835
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
A
42 "hi" 42 "हाय"
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
42hi 42हि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 42 and "hi". Output: 42 "hi".
व्याख्या (हिन्दी) 42 और "हाय"। आउटपुट: 42 "हाय"।
1836
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);} कॉउट
A
5 5
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) identity_(5)=5. Output: 5.
व्याख्या (हिन्दी) पहचान_(5)=5. आउटपुट: 5.
1837
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); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
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.
1838
EN + हिं
1839
EN + हिं
GB What is the output: template auto sumTuple(tuplet){return apply([](auto...xs){return (xs+...);},t);} cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो sumTuple(tuplet){return apply([](auto...xs){return (xs+...);},t);} cout
A
15 15
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
5 5
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+3+4+5=15. Output: 15.
व्याख्या (हिन्दी) 1+2+3+4+5=15. आउटपुट: 15.
1840
EN + हिं
GB What is the output: class Cache{mapm; functionf; public:Cache(functionfn):f(fn){} int get(int x){if(!m.count(x))m[x]=f(x);return m[x];}}; Cache sq([](int x){return x*x;}); cout<
IN आउटपुट क्या है: class Cache{mapm; फ़ंक्शनएफ; public:Cache(functionfn):f(fn){} int get(int x){if(!m.count(x))m[x]=f(x);return m[x];}}; कैश sq([](int x){रिटर्न x*x;}); अदालत
A
25259 25259
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
25 25 9 25 25 9
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) sq(5)=25 (computed); sq(5)=25 (cached); sq(3)=9. Output: 25259.
व्याख्या (हिन्दी) वर्ग(5)=25 (गणना); वर्ग(5)=25 (कैश्ड); वर्ग(3)=9. आउटपुट: 25259.
1841
EN + हिं
GB What is the output: class A{public:virtual int eval()const=0;}; class Const:public A{int v;public:Const(int x):v(x){} int eval()const override{return v;}}; class Mul:public A{A *l,*r;public:Mul(A*a,A*b):l(a),r(b){} int eval()const override{return l->eval()*r->eval();}}; A*e=new Mul(new Const(3),new Mul(new Const(4),new Const(5))); cout<eval();
IN आउटपुट क्या है: class A{public:virtual int eval()const=0;}; वर्ग स्थिरांक:सार्वजनिक A{int v;सार्वजनिक:Const(int x):v(x){} int eval()const ओवरराइड{रिटर्न v;}}; क्लास मुल:पब्लिक ए{ए *एल,*आर;पब्लिक:मुल(ए*ए,ए*बी):एल(ए),आर(बी){} int eval()const ओवरराइड{रिटर्न l->eval()*r->eval();}}; ए*ई=नया मूल(नया स्थिरांक(3),नया मूल(नया स्थिरांक(4),नया स्थिरांक(5))); अदालत
A
60 60
B
20 20
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 4*5=20; 3*20=60. Output: 60.
व्याख्या (हिन्दी) 4*5=20; 3*20=60. आउटपुट: 60.
1842
EN + हिं
GB What is the output: template auto zip_with(vectora,vectorb,functionf){vectorr;for(int i=0;i({1,2,3},{4,5,6},[](int a,int b){return a*b;}); cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो zip_with(vectora,vectorb,functionf){vectorr;for(int i=0;i)
A
10 10
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r[1]=2*5=10. Output: 10.
व्याख्या (हिन्दी) आर[1]=2*5=10. आउटपुट: 10.
1843
EN + हिं
GB What is the output: class Protocol{public:virtual void send(string)=0; virtual string recv()=0;}; class Echo:public Protocol{string last; public:void send(string s)override{last=s;} string recv()override{return last;}}; Echo e; e.send("hello"); cout<
IN आउटपुट क्या है: क्लास प्रोटोकॉल{पब्लिक:वर्चुअल वॉयड सेंड(स्ट्रिंग)=0; वर्चुअल स्ट्रिंग recv()=0;}; कक्षा इको: सार्वजनिक प्रोटोकॉल {स्ट्रिंग अंतिम; सार्वजनिक:शून्य भेजें(स्ट्रिंग s)ओवरराइड{अंतिम=s;} स्ट्रिंग recv()ओवरराइड{अंतिम वापसी;}}; इको ई; ई.भेजें('हैलो'); अदालत
A
hello नमस्ते
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) recv returns last sent. Output: hello.
व्याख्या (हिन्दी) recv रिटर्न अंतिम बार भेजा गया। आउटपुट: नमस्ते.
1844
EN + हिं
GB What is the output: template auto pipeline(T x){return x;} template auto pipeline(T x,F f,Fs...fs){return pipeline(f(x),fs...);} cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो पाइपलाइन(T x){रिटर्न x;} टेम्पलेट ऑटो पाइपलाइन(T x,F f,Fs...fs){रिटर्न पाइपलाइन(f(x),fs...);} cout
A
169 169
B
100 100
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10; 10+3=13; 13^2=169. Output: 169.
व्याख्या (हिन्दी) 5*2=10; 10+3=13; 13^2=169. आउटपुट: 169.
1845
EN + हिं
GB What is the output: class A{public:virtual int f()const=0; int g()const{return f()*f()+f();}}; class B:public A{public:int f()const override{return 3;}}; B b; cout<
IN आउटपुट क्या है: class A{public:virtual int f()const=0; int g()const{return f()*f()+f();}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f() स्थिरांक ओवरराइड {वापसी 3;}}; बी बी; अदालत
A
12 12
B
9 9
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3*3+3=12. Output: 12.
व्याख्या (हिन्दी) 3*3+3=12. आउटपुट: 12.
1831–1845 of 1915