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
1786
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual ~A()=default;}; class B:public A{int x; public:B(int v):x(v){} void f()override{cout<>v; v.push_back(make_shared(5)); v.push_back(make_shared(10)); for(auto&p:v)p->f();
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; कक्षा बी:सार्वजनिक ए{int x; सार्वजनिक:B(int v):x(v){} void f()ओवरराइड{cout
A
510 510
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
5 10 5 10
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() prints x. Output: 510.
व्याख्या (हिन्दी) B::f() x प्रिंट करता है। आउटपुट: 510.
1787
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; A* p=new B; cout<
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1B 1बी
B
1A 1 क
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) typeid(*p) with virtual = B's typeinfo. GCC: '1B'. Output: 1B.
व्याख्या (हिन्दी) टाइपआईडी(*पी) वर्चुअल = बी के टाइपइन्फो के साथ। जीसीसी: '1बी'. आउटपुट: 1बी.
1788
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual ~A()=default;}; class B:public A{public:void f()override{}}; A *p=new B; delete p; cout<<'X';
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; class B:public A{public:void f()override{}}; ए *पी=नया बी; पी हटाएं; अदालत
A
X एक्स
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
UB यूबी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual dtor ensures proper cleanup. Output: X.
व्याख्या (हिन्दी) वर्चुअल डीटोर उचित सफाई सुनिश्चित करता है। आउटपुट: एक्स.
1789
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;} int h(){return f()*f();}}; class B:public A{public:int f()override{return 3;}}; B b; cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;} इंट एच(){रिटर्न एफ()*एफ();}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 3;}}; बी बी; अदालत
A
9 9
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=3. h()=3*3=9. Output: 9.
व्याख्या (हिन्दी) बी::एफ()=3. एच()=3*3=9. आउटपुट: 9.
1790
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; B b; A &r=b; r.f();B &rb=b;rb.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
22 22
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both r.f() and rb.f() dispatch to B::f()=2. Output: 22.
व्याख्या (हिन्दी) r.f() और rb.f() दोनों B::f()=2 को भेजते हैं। आउटपुट: 22.
1791
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; mapm;m["a"]=new A;m["b"]=new B; for(auto&[k,v]:m)v->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
21 21
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Sorted keys: a=A=1, b=B=2. Output: 12.
व्याख्या (हिन्दी) क्रमबद्ध कुंजियाँ: a=A=1, b=B=2. आउटपुट: 12.
1792
EN + हिं
GB What is the output: class A{int x=5; public:int get()const{return x;} void set(int v){if(v>0)x=v;}}; A a; a.set(-3); cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक:int get()const{return x;} void set(int v){if(v>0)x=v;}}; ए ए; ए.सेट(-3); अदालत
A
57 57
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Rejected -3; 7 accepted. Output: 57.
व्याख्या (हिन्दी) अस्वीकृत -3; 7 स्वीकृत. आउटपुट: 57.
1793
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int get()const{return x;} A operator+(const A& o)const{return {x+o.x};}}; A a(3),b(4); A c=a+b; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int get()const{return x;} A ऑपरेटर+(const A& o)const{return {x+o.x};}}; ए ए(3),बी(4); ए सी=ए+बी; अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
1794
EN + हिं
GB What is the output: class A{int x=0,y=0; public:void setX(int v){x=v;} void setY(int v){y=v;} int sum()const{return x+y;}}; A a; a.setX(3); a.setY(4); cout<
IN आउटपुट क्या है: class A{int x=0,y=0; सार्वजनिक:void setX(int v){x=v;} void setY(int v){y=v;} int sum()const{return x+y;}}; ए ए; ए.सेटएक्स(3); a.setY(4); अदालत
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
1795
EN + हिं
GB What is the output: class A{vectorv; public:void add(int x){if(x>=0)v.push_back(x);} int max()const{return *max_element(v.begin(),v.end());}}; A a; a.add(-1);a.add(3);a.add(7);a.add(-2);a.add(5); cout<
IN आउटपुट क्या है: class A{vectorv; सार्वजनिक:शून्य जोड़ें(int x){if(x>=0)v.push_back(x);} int max()const{return *max_element(v.begin(),v.end());}}; ए ए; a.जोड़ें(-1);a.जोड़ें(3);a.जोड़ें(7);a.जोड़ें(-2);a.जोड़ें(5); अदालत
A
7 7
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Valid: 3,7,5. max=7. Output: 7.
व्याख्या (हिन्दी) मान्य: 3,7,5. अधिकतम=7. आउटपुट: 7.
1796
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int get()const{return x;} A& operator*=(int n){x*=n;return *this;}}; A a(3); a*=2; a*=3; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int get()const{return x;} A& ऑपरेटर*=(int n){x*=n;return *this;}}; ए ए(3); ए*=2; ए*=3; अदालत
A
18 18
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3*2=6; 6*3=18. Output: 18.
व्याख्या (हिन्दी) 3*2=6; 6*3=18. आउटपुट: 18.
1797
EN + हिं
GB What is the output: class Safe{int arr[10]={0}; public:int& at(int i){if(i<0||i>=10)throw out_of_range("OOB");return arr[i];}}; Safe s; s.at(3)=42; cout<
IN आउटपुट क्या है: class Safe{int arr[10]={0}; public:int& at(int i){if(i=10)throw out_of_range("OOB");return arr[i];}}; सुरक्षित एस; s.at(3)=42; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) at(3)=42. Output: 42.
व्याख्या (हिन्दी) at(3)=42. आउटपुट: 42.
1798
EN + हिं
GB What is the output: class A{int x=0; public:int get()const{return x;} void reset(){x=0;} A& set(int v){x=v;return *this;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:int get()const{return x;} void रीसेट(){x=0;} A& set(int v){x=v;return *this;}}; ए ए; अदालत
A
50 50
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.set(5).get()=5; a.reset() (returns void); comma op; a.get()=0. Output: 50.
व्याख्या (हिन्दी) a.set(5).get()=5; a.reset() (शून्य रिटर्न); अल्पविराम सेशन; a.get()=0. आउटपुट: 50.
1799
EN + हिं
GB What is the output: class A{int x; public:A(int v=0):x(v){} bool isValid()const{return x>=0&&x<=100;} void clip(){if(x<0)x=0;if(x>100)x=100;}}; A a(-5); a.clip(); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:A(int v=0):x(v){} bool isValid()const{return x>=0&&x
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) clip sets x=0. isValid()=1. Output: 1.
व्याख्या (हिन्दी) क्लिप सेट x=0. वैध()=1 है। आउटपुट: 1.
1800
EN + हिं
GB What is the output: class A{int x=1,y=2,z=3; public:auto getAll()const{return make_tuple(x,y,z);}}; A a; auto [x,y,z]=a.getAll(); cout<
IN आउटपुट क्या है: class A{int x=1,y=2,z=3; सार्वजनिक:ऑटो getAll()const{return make_tuple(x,y,z);}}; ए ए; ऑटो [x,y,z]=a.getAll(); अदालत
A
6 6
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+3=6. Output: 6.
व्याख्या (हिन्दी) 1+2+3=6. आउटपुट: 6.
1786–1800 of 1915