OOP Using C++ — MCQ Practice

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

📚 106 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
106 questions
76
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} void print()const{cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} void print()const{cout
A
7 7
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5+1+1=7. Output: 7.
व्याख्या (हिन्दी) 5+1+1=7. आउटपुट: 7.
77
EN + हिं
GB What is the output: class A{public:int x=0; A& add(int v){x+=v;return *this;} A& mul(int v){x*=v;return *this;}}; A a; cout<
IN आउटपुट क्या है: class A{public:int x=0; A& add(int v){x+=v;return *this;} A& mul(int v){x*=v;return *this;}}; ए ए; अदालत
A
14 14
B
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 0+3=3; +4=7; *2=14. Output: 14.
व्याख्या (हिन्दी) 0+3=3; +4=7; *2=14. आउटपुट: 14.
78
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A operator-()const{return A(-x);}}; A a(5); cout<<(-a).x;
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A ऑपरेटर-()const{return A(-x);}}; ए ए(5); अदालत
A
-5 -5
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) (-a).x=-5. Output: -5.
व्याख्या (हिन्दी) (-a).x=-5. आउटपुट:-5.
79
EN + हिं
GB What is the output: class A{public:int x=0; A(int v=0):x(v){} bool operator<(const A& o)const{return xv={{5},{3},{8},{1}}; sort(v.begin(),v.end()); cout<
IN आउटपुट क्या है: class A{public:int x=0; A(int v=0):x(v){} बूल ऑपरेटर
A
18 18
B
81 81
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Sorted: 1,3,5,8. v[0].x=1,v[3].x=8. Output: 18.
व्याख्या (हिन्दी) क्रमबद्ध: 1,3,5,8. v[0].x=1,v[3].x=8. आउटपुट: 18.
80
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){x=o.x; return *this;}}; A a(3),b(5); a=b=A(10); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} int get()const{return x;} A& ऑपरेटर=(const A& o){x=o.x; वापसी *यह;}}; ए ए(3),बी(5); ए=बी=ए(10); अदालत
A
1010 1010
B
35 35
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b=A(10): b.x=10; a=b: a.x=10. Output: 1010.
व्याख्या (हिन्दी) b=A(10): b.x=10; a=b: a.x=10. आउटपुट: 1010.
81
EN + हिं
GB What is the output: class Vec{public:double x,y; Vec(double a,double b):x(a),y(b){} double dot(const Vec& v)const{return x*v.x+y*v.y;}}; Vec a(1,2),b(3,4); cout<
IN आउटपुट क्या है: class Vec{public:double x,y; Vec(double a,double b):x(a),y(b){} डबल डॉट(const Vec& v)const{return x*v.x+y*v.y;}}; Vec a(1,2),b(3,4); अदालत
A
11 11
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1*3+2*4=11. Output: 11.
व्याख्या (हिन्दी) 1*3+2*4=11. आउटपुट: 11.
82
EN + हिं
GB What is the output: class A{public:int x=0; void set(int v){x=v;} void reset(){x=0;} int get()const{return x;}}; A a; a.set(5); cout<
IN आउटपुट क्या है: class A{public:int x=0; शून्य सेट(int v){x=v;} शून्य रीसेट(){x=0;} int get()const{return x;}}; ए ए; ए.सेट(5); अदालत
A
50 50
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5 then 0. Output: 50.
व्याख्या (हिन्दी) 5 फिर 0. आउटपुट: 50.
83
EN + हिं
GB What is the output: class A{public:int data[3]; A(int a,int b,int c){data[0]=a;data[1]=b;data[2]=c;} int& operator[](int i){return data[i];}}; A a(1,2,3); a[1]=10; cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:इंट डेटा[3]; A(int a,int b,int c){data[0]=a;data[1]=b;data[2]=c;} int& ऑपरेटर[](int i){return data[i];}}; ए ए(1,2,3); ए[1]=10; अदालत
A
1103 1103
B
123 123
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a[1]=10. Output: 1103.
व्याख्या (हिन्दी) ए[1]=10. आउटपुट: 1103.
84
EN + हिं
GB What is the output: class A{public:int x; 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+a.x);}}; A a(5); cout<<(a+3).x<<(3+a).x;
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A ऑपरेटर+(int n)const{रिटर्न A(x+n);} मित्र A ऑपरेटर+(int n,const A& a){रिटर्न A(n+a.x);}}; ए ए(5); अदालत
A
88 88
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
8 8 8 8
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a+3=8; 3+a=8. Output: 88.
व्याख्या (हिन्दी) ए+3=8; 3+ए=8. आउटपुट: 88.
85
EN + हिं
GB What is the output: class A{int x=1; public: class B{int y=2; public: void f(A& a){cout<
IN आउटपुट क्या है: class A{int x=1; सार्वजनिक: वर्ग B{int y=2; सार्वजनिक: शून्य f(A&a){cout
A
3 3
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
2 2
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f accesses A::x=1. 1+2=3. Output: 3.
व्याख्या (हिन्दी) B::f A::x=1 तक पहुँचता है। 1+2=3. आउटपुट: 3.
86
EN + हिं
GB What is the output: class A{public:int v; explicit A(int x):v(x){} explicit operator int()const{return v;}}; A a(5); cout<<(int)a;
IN आउटपुट क्या है: class A{public:int v; स्पष्ट A(int x):v(x){} स्पष्ट ऑपरेटर int()const{return v;}}; ए ए(5); अदालत
A
5 5
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) explicit operator int: explicit cast works. Output: 5.
व्याख्या (हिन्दी) स्पष्ट ऑपरेटर int: स्पष्ट कास्ट काम करता है। आउटपुट: 5.
87
EN + हिं
GB What is the output: class A{public:int x=5; int f()const{return x;} int g(){return x*2;}}; const A a; cout<
IN आउटपुट क्या है: class A{public:int x=5; int f()const{रिटर्न x;} int g(){रिटर्न x*2;}}; स्थिरांक ए ए; अदालत
A
5 5
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) const A calls f()=5. Output: 5.
व्याख्या (हिन्दी) स्थिरांक A f()=5 कहता है। आउटपुट: 5.
88
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(const A& o):x(o.x){} A& operator=(A o){swap(x,o.x);return *this;}}; A a(3),b(5); a=b; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A(const A& o):x(o.x){} A& ऑपरेटर=(A o){swap(x,o.x);return *this;}}; ए ए(3),बी(5); ए=बी; अदालत
A
53 53
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=b: copy b to o(x=5), swap a.x and o.x: a.x=5,o.x=3. Output: 53.
व्याख्या (हिन्दी) a=b: b को o(x=5) पर कॉपी करें, a.x और o.x को स्वैप करें: a.x=5,o.x=3. आउटपुट: 53.
89
EN + हिं
GB What is the output: class A{public:int n; A(int v):n(v){} bool operator==(const A& o)const{return n==o.n;} bool operator!=(const A& o)const{return !(*this==o);}}; A a(3),b(3),c(4); cout<<(a==b)<<(a!=c);
IN आउटपुट क्या है: class A{public:int n; A(int v):n(v){} bool ऑपरेटर==(const A&o)const{return n==on.n;} बूल ऑपरेटर!=(const A& o)const{return !(*this==o);}}; ए ए(3),बी(3),सी(4); अदालत
A
11 11
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3==3=1; 3!=4=1. Output: 11.
व्याख्या (हिन्दी) 3==3=1; 3!=4=1. आउटपुट: 11.
90
EN + हिं
GB What is the output: class A{mutable int cache=-1; public:int compute(int x)const{if(cache==-1)cache=x*x; return cache;}}; const A a; cout<
IN आउटपुट क्या है: क्लास ए{म्यूटेबल इंट कैश=-1; सार्वजनिक:int कंप्यूट(int x)const{if(cache==-1)cache=x*x; कैश वापसी;}}; स्थिरांक ए ए; अदालत
A
2525 2525
B
2536 2536
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) First call: cache=25. Second call: cache already set=25. Output: 2525.
व्याख्या (हिन्दी) पहली कॉल: कैश=25. दूसरा कॉल: कैश पहले से ही सेट = 25। आउटपुट: 2525.
76–90 of 106