OOP Using C++ — MCQ Practice

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

📚 107 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
107 questions
61
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} void set(int v){x=(v>0?v:x);}}; A a; a.set(-1); a.set(5); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} void set(int v){x=(v>0?v:x);}}; ए ए; ए.सेट(-1); ए.सेट(5); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -1 rejected; 5 accepted. x=5. Output: 5.
व्याख्या (हिन्दी) -1 अस्वीकृत; 5 स्वीकृत. एक्स=5. आउटपुट: 5.
62
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} operator string()const{return to_string(x);}}; A a(42); string s=a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} ऑपरेटर स्ट्रिंग()const{return to_string(x);}}; ए ए(42); स्ट्रिंग एस=ए; अदालत
A
42 42
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator string() returns "42". s="42". Output: 42.
व्याख्या (हिन्दी) ऑपरेटर स्ट्रिंग() "42" लौटाता है। एस='42' आउटपुट: 42.
63
EN + हिं
GB What is the output: class A{vector v; public: void add(int x){v.push_back(x);} int size()const{return v.size();} int at(int i)const{return v.at(i);}}; A a; a.add(1);a.add(2);a.add(3); cout<
IN आउटपुट क्या है: क्लास ए {वेक्टर वी; सार्वजनिक: void add(int x){v.push_back(x);} int size()const{return v.size();} int at(int i)const{return v.at(i);}}; ए ए; a.जोड़ें(1);a.जोड़ें(2);a.जोड़ें(3); अदालत
A
32 32
B
23 23
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) size=3, at(1)=2. Output: 32.
व्याख्या (हिन्दी) आकार=3, पर(1)=2. आउटपुट: 32.
64
EN + हिं
GB What is the output: class A{int x=0; public: A& operator+=(int v){x+=v;return *this;} operator int()const{return x;}}; A a; a+=5; a+=3; cout<<(int)a;
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: A& ऑपरेटर+=(int v){x+=v;रिटर्न *यह;} ऑपरेटर int()const{रिटर्न x;}}; ए ए; ए+=5; ए+=3; अदालत
A
8 8
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=5+3=8. operator int()=8. Output: 8.
व्याख्या (हिन्दी) x=5+3=8. ऑपरेटर int()=8. आउटपुट: 8.
65
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} friend A operator+(A a,const A& b){a.x+=b.x;return a;}}; A a; a.x; int y=0; //can't access x directly, use friend
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} मित्र A ऑपरेटर+(A a,const A& b){a.x+=b.x;return a;}}; ए ए; a.x; int y=0; // सीधे x तक नहीं पहुंच सकता, मित्र का उपयोग करें
A
Compile error (can't set x from outside) संकलन त्रुटि (बाहर से x सेट नहीं किया जा सकता)
B
Works with friend दोस्त के साथ काम करता है
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Friend operator+ can access x. Output depends on usage.
व्याख्या (हिन्दी) मित्र ऑपरेटर+ x तक पहुंच सकता है। आउटपुट उपयोग पर निर्भर करता है।
66
EN + हिं
GB What is the output: class A{int x=0; public: void f(){x++;} int g()const{return x;}}; A *p=new A[3]; for(int i=0;i<3;i++) p[i].f(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void f(){x++;} int g()const{return x;}}; ए *पी=नया ए[3]; for(int i=0;i
A
1 1
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each object gets its own x. p[1].f(): x=1. p[1].g()=1. Output: 1.
व्याख्या (हिन्दी) प्रत्येक वस्तु को अपना स्वयं का x मिलता है। पी[1].एफ(): x=1. पी[1].जी()=1. आउटपुट: 1.
67
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} void f(A& o){o.x=x+1;}}; A a,b; a.f(b); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} void f(A& o){o.x=x+1;}}; ए ए, बी; ए.एफ(बी); अदालत
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f accesses b.x=a.x+1=0+1=1. Output: 1.
व्याख्या (हिन्दी) f b.x=a.x+1=0+1=1 तक पहुँचता है। आउटपुट: 1.
68
EN + हिं
GB What is the output: class A{int x=0; public: void set(int v){if(v>=0&&v<=100) x=v;} int get()const{return x;}}; A a; a.set(200); a.set(50); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: शून्य सेट(int v){if(v>=0&&v
A
50 50
B
200 200
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 200 rejected; 50 accepted. x=50. Output: 50.
व्याख्या (हिन्दी) 200 अस्वीकृत; 50 स्वीकृत। एक्स=50. आउटपुट: 50.
69
EN + हिं
GB What is the output: class A{int x=5; public: A& operator=(int v){x=v;return *this;} operator int(){return x;}}; A a; a=10; cout<<(int)a;
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: A& ऑपरेटर=(int v){x=v;रिटर्न *यह;} ऑपरेटर int(){रिटर्न x;}}; ए ए; ए=10; अदालत
A
10 10
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=10: x=10. (int)a=10. Output: 10.
व्याख्या (हिन्दी) ए=10: एक्स=10. (int)a=10. आउटपुट: 10.
70
EN + हिं
GB What is the output: class A{vector v; public: void add(int x){v.push_back(x);} int sum()const{return accumulate(v.begin(),v.end(),0);}}; A a; a.add(1);a.add(2);a.add(3); cout<
IN आउटपुट क्या है: क्लास ए {वेक्टर वी; सार्वजनिक: void add(int x){v.push_back(x);} int sum()const{return generate(v.begin(),v.end(),0);}}; ए ए; a.जोड़ें(1);a.जोड़ें(2);a.जोड़ें(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.
71
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} int operator-()const{return -x;} int operator+()const{return +x;}}; A a(5); cout<<-a<<+a;
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} int ऑपरेटर-()const{return -x;} int ऑपरेटर+()const{return +x;}}; ए ए(5); अदालत
A
-55 -55
B
5-5 5-5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -a=-5; +a=5. Output: -55.
व्याख्या (हिन्दी) -ए=-5; +ए=5. आउटपुट:-55.
72
EN + हिं
GB What is the output: class A{int n=0; public: A& operator+=(int v){n+=v;return *this;} A& operator-=(int v){n-=v;return *this;} int get()const{return n;}}; A a; a+=5; a+=3; a-=2; cout<
IN आउटपुट क्या है: class A{int n=0; सार्वजनिक: A& ऑपरेटर+=(int v){n+=v;रिटर्न *यह;} A& ऑपरेटर-=(int v){n-=v;रिटर्न *यह;} int get()const{रिटर्न n;}}; ए ए; ए+=5; ए+=3; ए-=2; अदालत
A
6 6
B
8 8
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5+3-2=6. Output: 6.
व्याख्या (हिन्दी) 5+3-2=6. आउटपुट: 6.
73
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} A operator*(int n)const{return A(x*n);} friend A operator*(int n,const A& a){return a*n;} int get()const{return x;}}; A a(3); cout<<(a*4).get()<<(5*a).get();
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} A ऑपरेटर*(int n)const{return A(x*n);} मित्र A ऑपरेटर*(int n,const A& a){return a*n;} int get()const{return x;}}; ए ए(3); अदालत
A
1215 1215
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
12 15 12 15
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a*4=12; 5*a=15. Output: 1215.
व्याख्या (हिन्दी) ए*4=12; 5*ए=15. आउटपुट: 1215.
74
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.
75
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.
व्याख्या (हिन्दी) "हाय"+"वहां"="यहां"। आउटपुट: यहाँ.
61–75 of 107