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
976
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; try{A *p=new struct B:A{void f(){}}{};delete p;}catch(...){} cout<<'X';
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; प्रयास करें{A *p=नई संरचना B:A{void f(){}}{};delete p;}catch(...){} cout
A
Compile error संकलन त्रुटि
B
X एक्स
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inline struct definition in new is not valid C++. Compile error.
व्याख्या (हिन्दी) नई में इनलाइन संरचना परिभाषा मान्य C++ नहीं है। संकलन त्रुटि.
977
EN + हिं
GB What is the output: class Memo{mapm; public: int f(int n){if(m.count(n))return m[n]; return m[n]=n<=1?n:f(n-1)+f(n-2);}}; Memo memo; cout<
IN आउटपुट क्या है: क्लास मेमो{मैपम; सार्वजनिक: int f(int n){if(m.count(n))रिटर्न m[n]; वापसी एम[एन]=एन
A
55 55
B
34 34
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Fib(10)=55. Output: 55.
व्याख्या (हिन्दी) फ़िब(10)=55. आउटपुट: 55.
978
EN + हिं
GB What is the output: class Builder{int x=0,y=0; public: Builder& setX(int v){x=v;return *this;} Builder& setY(int v){y=v;return *this;} int build(){return x+y;}}; cout<
IN आउटपुट क्या है: क्लास बिल्डर{int x=0,y=0; सार्वजनिक: Builder& setX(int v){x=v;return *this;} Builder& setY(int v){y=v;return *this;} int build(){return x+y;}}; अदालत
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
979
EN + हिं
GB What is the output: class A{public:virtual int f()const=0;}; class B:public A{int v; public:B(int v):v(v){} int f()const override{return v*v;}}; vector> v; v.push_back(make_unique(3)); v.push_back(make_unique(4)); int s=0; for(auto&p:v)s+=p->f(); cout<
IN आउटपुट क्या है: class A{public:virtual int f()const=0;}; कक्षा बी:सार्वजनिक ए{इंट वी; सार्वजनिक:बी(int v):v(v){} int f()const ओवरराइड{रिटर्न v*v;}}; वेक्टर वी; v.push_back(make_unique(3)); v.push_back(make_unique(4)); int s=0; for(auto&p:v)s+=p->f(); अदालत
A
25 25
B
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 9+16=25. Output: 25.
व्याख्या (हिन्दी) 9+16=25. आउटपुट: 25.
980
EN + हिं
GB What is the output: class Pipe{vector>fns; public: Pipe& add(functionf){fns.push_back(f);return *this;} int run(int x){for(auto&f:fns)x=f(x);return x;}}; Pipe p; p.add([](int x){return x*2;}).add([](int x){return x+3;}).add([](int x){return x*x;}); cout<
IN आउटपुट क्या है: class Pipe{vectorfns; सार्वजनिक: Pipe& add(functionf){fns.push_back(f);return *this;} int run(int x){for(auto&f:fns)x=f(x);return x;}}; पाइप पी; p.add([](int x){return x*2;}).add([](int x){return x+3;}).add([](int x){return x*x;}); अदालत
A
169 169
B
100 100
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) (5*2+3)^2=(10+3)^2=169. Output: 169.
व्याख्या (हिन्दी) (5*2+3)^2=(10+3)^2=169. आउटपुट: 169.
981
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; class C:public A{public:void f()override{cout<<'C';}}; map> m; m["b"]=make_unique(); m["c"]=make_unique(); for(auto&[k,v]:m) v->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
BC ईसा पूर्व
B
CB सीबी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) map ordered: b
व्याख्या (हिन्दी) मानचित्र का आदेश दिया गया: बी
982
EN + हिं
GB What is 'interface segregation principle' in C++?
IN C++ में 'इंटरफ़ेस पृथक्करण सिद्धांत' क्या है?
A
Split large interfaces into smaller specific ones बड़े इंटरफ़ेस को छोटे विशिष्ट इंटरफ़ेस में विभाजित करें
B
Combine all interfaces सभी इंटरफ़ेस को संयोजित करें
C
Use only abstract classes केवल अमूर्त वर्गों का प्रयोग करें
D
PIMPL pattern पीआईएमपीएल पैटर्न
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ISP: clients depend only on interfaces they use; prevents fat interfaces with unused methods.
व्याख्या (हिन्दी) आईएसपी: ग्राहक केवल उनके द्वारा उपयोग किए जाने वाले इंटरफेस पर निर्भर करते हैं; अप्रयुक्त तरीकों से वसा इंटरफेस को रोकता है।
983
EN + हिं
984
EN + हिं
GB What is the output: template auto call(F f,Args...args){return f(args...);} cout<
IN आउटपुट क्या है: टेम्पलेट ऑटो कॉल(F f,Args...args){रिटर्न f(args...);} cout
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.
985
EN + हिं
GB What is the output: class FSM{int state=0; public: void trans(int t){state=(state+t)%3;} int get()const{return state;}}; FSM m; m.trans(1);m.trans(2);m.trans(1); cout<
IN आउटपुट क्या है: class FSM{int state=0; सार्वजनिक: void trans(int t){state=(state+t)%3;} int get()const{return state;}}; एफएसएम एम; एम.ट्रांस(1);एम.ट्रांस(2);एम.ट्रांस(1); अदालत
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) state: 0->1->0->1. Output: 1. Wait: 0+1=1%3=1; 1+2=3%3=0; 0+1=1%3=1. Output: 1.
व्याख्या (हिन्दी) अवस्था: 0->1->0->1. आउटपुट: 1. प्रतीक्षा करें: 0+1=1%3=1; 1+2=3%3=0; 0+1=1%3=1. आउटपुट: 1.
986
EN + हिं
GB What is the output: class Command{public:virtual void exec()=0;}; class Print:public Command{string s; public:Print(string t):s(t){} void exec(){cout<> cmds; cmds.push_back(make_unique("A")); cmds.push_back(make_unique("B")); for(auto&c:cmds) c->exec();
IN आउटपुट क्या है: class Command{public:virtual void exec()=0;}; क्लास प्रिंट:पब्लिक कमांड{स्ट्रिंग एस; सार्वजनिक: प्रिंट (स्ट्रिंग टी): एस (टी) {} शून्य निष्पादन () {काउट
A
AB अब
B
BA बी ० ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Print A then B. Output: AB.
व्याख्या (हिन्दी) ए फिर बी प्रिंट करें। आउटपुट: एबी।
987
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; auto wrap=[](A* p)->function{return [p]{p->f();};}; auto fn=wrap(new B); fn();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=2. Output: 2.
व्याख्या (हिन्दी) बी::एफ()=2. आउटपुट: 2.
988
EN + हिं
GB What is the output: try{throw 5;}catch(int i){cout<
IN आउटपुट क्या है: Try{throw 5;}catch(int i){cout
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Catch int 5. Output: 5.
व्याख्या (हिन्दी) कैच इंट 5. आउटपुट: 5.
989
EN + हिं
GB What is the output: try{throw string("err");}catch(const string& s){cout<
IN आउटपुट क्या है: प्रयास करें {थ्रो स्ट्रिंग ("err");} पकड़ें (कॉन्स्ट स्ट्रिंग और एस) {काउट
A
3 3
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) "err".size()=3. Output: 3.
व्याख्या (हिन्दी) "त्रुटि"।आकार()=3। आउटपुट: 3.
990
EN + हिं
GB What is the output: struct E{int code; string msg;}; try{throw E{404,"not found"};}catch(E& e){cout<
IN आउटपुट क्या है: struct E{int कोड; स्ट्रिंग संदेश;}; प्रयास करें{फेंकें E{404,"नहीं मिला"};}पकड़ें(E& e){cout
A
404 404
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) e.code=404. Output: 404.
व्याख्या (हिन्दी) ई.कोड=404. आउटपुट: 404.
976–990 of 1915