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
1801
EN + हिं
GB What is the output: class A{int x=0; public:int get()const{return x;} void f(){x++;} void g(){f();f();f();}}; A a; a.g(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:int get()const{return x;} void f(){x++;} void g(){f();f();f();}}; ए ए; a.g(); अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls f() 3 times: x=3. Output: 3.
व्याख्या (हिन्दी) g() f() को 3 बार कॉल करता है: x=3। आउटपुट: 3.
1802
EN + हिं
GB What is the output: class A{int n; public:A(int v):n(v){} auto begin(){return &n;} auto end(){return &n+1;}}; A a(42); for(int x:a) cout<
IN आउटपुट क्या है: class A{int n; सार्वजनिक:ए(int v):n(v){} ऑटो प्रारंभ(){रिटर्न &n;} ऑटो एंड(){रिटर्न &n+1;}}; ए ए(42); for(int x:a) कोउट
A
42 42
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Iterates single element 42. Output: 42.
व्याख्या (हिन्दी) एकल तत्व को पुनरावृत्त करता है 42. आउटपुट: 42.
1803
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int operator()(int y)const{return x*y;} int operator()(int y,int z)const{return x*(y+z);}}; A a(3); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int ऑपरेटर()(int y)const{रिटर्न x*y;} int ऑपरेटर()(int y,int z)const{रिटर्न x*(y+z);}}; ए ए(3); अदालत
A
1227 1227
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
12 27 12 27
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a(4)=3*4=12; a(4,5)=3*9=27. Output: 1227.
व्याख्या (हिन्दी) ए(4)=3*4=12; a(4,5)=3*9=27. आउटपुट: 1227.
1804
EN + हिं
GB What is the output: class A{int x=0; public:A& inc(){x++;return *this;} A& mul(int n){x*=n;return *this;} int val()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:A& inc(){x++;return *this;} A& mul(int n){x*=n;return *this;} int val()const{return x;}}; ए ए; अदालत
A
9 9
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 0+1+1+1=3; 3*3=9. Output: 9.
व्याख्या (हिन्दी) 0+1+1+1=3; 3*3=9. आउटपुट: 9.
1805
EN + हिं
GB What is the output: class A{int x; public:explicit A(int v):x(v){} A operator-()const{return A(-x);} int get()const{return x;}}; A a(5); A b=-a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:स्पष्ट A(int v):x(v){} A ऑपरेटर-()const{return A(-x);} int get()const{return x;}}; ए ए(5); ए बी=-ए; अदालत
A
-5 -5
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -a: operator-() returns A(-5). b.get()=-5. Output: -5.
व्याख्या (हिन्दी) -ए: ऑपरेटर-() रिटर्न ए(-5)। बी.प्राप्त()=-5. आउटपुट:-5.
1806
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.
1807
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.
1808
EN + हिं
1809
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.
1810
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.
1811
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.
1812
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.
1813
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.
1814
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.
1815
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.
1801–1815 of 1915