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
91
EN + हिं
GB What is the output: class Stack{vectors; public:void push(int x){s.push_back(x);} int top()const{return s.back();} void pop(){s.pop_back();} bool empty()const{return s.empty();} int size()const{return s.size();}}; Stack st; st.push(1);st.push(2);st.push(3); cout<
IN आउटपुट क्या है: क्लास स्टैक {वेक्टर; सार्वजनिक: शून्य पुश (इंट एक्स) {एस पुश_बैक (एक्स); ढेर सेंट; st.push(1);st.push(2);st.push(3); अदालत
A
332 332
B
123 123
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) top=3,size=3; pop; top=2. Output: 332.
व्याख्या (हिन्दी) शीर्ष=3,आकार=3; जल्दी से आना; शीर्ष=2. आउटपुट: 332.
92
EN + हिं
GB What is the output: class A{int x=0; public:void set(int v){x=v%10;} int get()const{return x;}}; A a; a.set(42); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:शून्य सेट(int v){x=v%10;} int get()const{return x;}}; ए ए; ए.सेट(42); अदालत
A
2 2
B
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 42%10=2. Output: 2.
व्याख्या (हिन्दी) 42%10=2. आउटपुट: 2.
93
EN + हिं
94
EN + हिं
GB What is the output: class A{int x=0; public:A& operator<<(int v){x+=v;return *this;} int get()const{return x;}}; A a; a<<1<<2<<3<<4<<5; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:ए एवं ऑपरेटर
A
15 15
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 0+1+2+3+4+5=15. Output: 15.
व्याख्या (हिन्दी) 0+1+2+3+4+5=15. आउटपुट: 15.
95
EN + हिं
GB What is the output: class A{int x; public:explicit A(int v):x(v){} int get()const{return x;} A& operator++(){++x;return *this;} A operator++(int){auto t=*this;++*this;return t;}}; A a(3); cout<<(a++).get()<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:स्पष्ट A(int v):x(v){} int get()const{return x;} A& ऑपरेटर++(){++x;रिटर्न *यह;} A ऑपरेटर++(int){auto t=*this;++*this;रिटर्न t;}}; ए ए(3); अदालत
A
345 345
B
344 344
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a++=3(a=4); a.get()=4; ++a=5. Output: 345.
व्याख्या (हिन्दी) ए++=3(ए=4); a.get()=4; ++ए=5. आउटपुट: 345.
96
EN + हिं
GB What is the output: class A{string name_; public:A(string n):name_(n){} const string& name()const{return name_;} bool operator==(const A& o)const{return name_==o.name_;}}; A a("Bob"),b("Bob"),c("Alice"); cout<<(a==b)<<(a==c);
IN आउटपुट क्या है: क्लास ए{स्ट्रिंग नाम_; सार्वजनिक:ए(स्ट्रिंग एन):नाम_(एन){} स्थिरांक स्ट्रिंग&नाम()स्थिरांक{वापसी नाम_;} बूल ऑपरेटर==(स्थिरांक ए&ओ)स्थिरांक{वापसी नाम_==ओ.नाम_;}}; ए ए("बॉब"),बी("बॉब"),सी("ऐलिस"); अदालत
A
10 10
B
01 01
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Bob==Bob=1; Bob==Alice=0. Output: 10.
व्याख्या (हिन्दी) बॉब==बॉब=1; बॉब==ऐलिस=0. आउटपुट: 10.
97
EN + हिं
GB What is the output: class A{int n=0; public:void add(int x){n+=x;} void sub(int x){n-=x;} void neg(){n=-n;} int get()const{return n;}}; A a; a.add(5);a.add(3);a.neg();a.sub(2); cout<
IN आउटपुट क्या है: class A{int n=0; सार्वजनिक: शून्य जोड़ें (int x) {n + = x;} शून्य उप (int x) {n- = x;} शून्य नकारात्मक() {n = - n;} int get() स्थिरांक {वापसी n;}}; ए ए; a.add(5);a.add(3);a.neg();a.sub(2); अदालत
A
-10 -10
B
-8 -8
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 0+5+3=8; neg=-8; -8-2=-10. Output: -10.
व्याख्या (हिन्दी) 0+5+3=8; नकारात्मक=-8; -8-2=-10. आउटपुट:-10.
98
EN + हिं
GB What is the output: class A{int x,y; public:A(int a,int b):x(a),y(b){} A scale(int n)const{return {x*n,y*n};} int mag2()const{return x*x+y*y;}}; A a(3,4); cout<
IN आउटपुट क्या है: class A{int x,y; सार्वजनिक:ए(int a,int b):x(a),y(b){} A स्केल(int n)const{return {x*n,y*n};} intmag2()const{return x*x+y*y;}}; ए ए(3,4); अदालत
A
100 100
B
25 25
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) scale(2)=(6,8); mag2=36+64=100. Output: 100.
व्याख्या (हिन्दी) स्केल(2)=(6,8); Mag2=36+64=100. आउटपुट: 100.
99
EN + हिं
GB What is the output: class A{int x=5; public:const int& cref()const{return x;} int& ref(){return x;}}; A a; a.ref()=10; cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक:const int& cref()const{return x;} int& ref(){return x;}}; ए ए; a.ref()=10; अदालत
A
10 10
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ref()=x=10; cref()=10. Output: 10.
व्याख्या (हिन्दी) रेफरी()=x=10; क्रेफ़()=10. आउटपुट: 10.
100
EN + हिं
GB What is the output: class Acc{double s=0,n=0; public:void add(double x){s+=x;n++;} double mean()const{return n?s/n:0;}}; Acc acc; acc.add(2);acc.add(4);acc.add(6); cout<
IN आउटपुट क्या है: class Acc{double s=0,n=0; सार्वजनिक:शून्य जोड़ें(डबल x){s+=x;n++;} डबल माध्य()const{रिटर्न n?s/n:0;}}; एसीसी एसीसी; acc.add(2);acc.add(4);acc.add(6); अदालत
A
4 4
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) (2+4+6)/3=4. Output: 4.
व्याख्या (हिन्दी) (2+4+6)/3=4. आउटपुट: 4.
101
EN + हिं
GB What is the output: class A{mapm; public:int& at(const string& k){return m[k];} int get(const string& k)const{auto it=m.find(k);return it!=m.end()?it->second:0;}}; A a; a.at("x")=5; cout<
IN आउटपुट क्या है: class A{mapm; public:int& at(const string& k){return m[k];} int get(const string& k)const{auto it=m.find(k);return it!=m.end()?it-> सेकेंड:0;}}; ए ए; a.at("x")=5; अदालत
A
50 50
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=5, y not found=0. Output: 50.
व्याख्या (हिन्दी) x=5, y नहीं मिला=0. आउटपुट: 50.
102
EN + हिं
GB What is the output: class A{int x=0; public:A& operator+=(const A& o){x+=o.x;return *this;} int get()const{return x;} A(int v=0):x(v){}}; A a(3),b(4); a+=b; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:A& ऑपरेटर+=(const A& o){x+=o.x;return *this;} int get()const{return x;} A(int v=0):x(v){}}; ए ए(3),बी(4); ए+=बी; अदालत
A
74 74
B
77 77
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=3+4=7; b.x=4 unchanged. Output: 74.
व्याख्या (हिन्दी) a.x=3+4=7; b.x=4 अपरिवर्तित. आउटपुट: 74.
103
EN + हिं
GB What is the output: class A{int x=0; public:operator bool()const{return x!=0;} void set(int v){x=v;}}; A a; cout<<(bool)a; a.set(5); cout<<(bool)a;
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: ऑपरेटर बूल() स्थिरांक {वापसी x! = 0;} शून्य सेट (int v) {x = v;}}; ए ए; अदालत
A
01 01
B
00 00
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=0: false=0; x=5: true=1. Output: 01.
व्याख्या (हिन्दी) x=0: गलत=0; x=5: सत्य=1. आउटपुट: 01.
104
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} A operator%(const A& o)const{return {x%o.x};} int get()const{return x;}}; A a(10),b(3); cout<<(a%b).get();
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} A ऑपरेटर%(const A& o)const{return {x%o.x};} int get()const{return x;}}; ए ए(10),बी(3); अदालत
A
1 1
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 10%3=1. Output: 1.
व्याख्या (हिन्दी) 10%3=1. आउटपुट: 1.
105
EN + हिं
GB What is the output: class A{int v=0; public:int peek()const{return v;} void push(int x){v=x;} int pop(){int t=v;v=0;return t;}}; A a; a.push(42); cout<
IN आउटपुट क्या है: class A{int v=0; सार्वजनिक:int peek()const{रिटर्न v;} void पुश(int x){v=x;} int पॉप(){int t=v;v=0;रिटर्न t;}}; ए ए; ए.पुश(42); अदालत
A
420 420
B
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) pop returns 42, v=0. peek=0. Output: 420.
व्याख्या (हिन्दी) पॉप रिटर्न 42, वी=0। झाँकना=0. आउटपुट: 420.
91–105 of 107