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
1351
EN + हिं
GB What is the output: class A{public:int x=5;}; class B{public:A a;}; B b; cout<
IN आउटपुट क्या है: class A{public:int x=5;}; कक्षा बी{सार्वजनिक:ए ए;}; बी बी; अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.a.x=5. Output: 5.
व्याख्या (हिन्दी) b.a.x=5. आउटपुट: 5.
1352
EN + हिं
GB What is the output: class A{public:int x=0; friend A operator+(A a,A b){return A(a.x+b.x); A(int v):x(v){}}};
IN आउटपुट क्या है: class A{public:int x=0; मित्र A ऑपरेटर+(A a,A b){रिटर्न A(a.x+b.x); A(int v):x(v){}}};
A
Compile error संकलन त्रुटि
B
Works काम करता है
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor A(int) defined after friend inside class — ill-formed. Compile error.
व्याख्या (हिन्दी) कंस्ट्रक्टर A(int) को कक्षा के अंदर मित्र के बाद परिभाषित किया गया - गलत तरीके से बनाया गया। संकलन त्रुटि.
1353
EN + हिं
GB What is the output: class A{public: int x=0; void f()&{x=1;} void f()&&{x=2;}}; A a; a.f(); cout<
IN आउटपुट क्या है: class A{public: int x=0; शून्य f()&{x=1;} शून्य f()&&{x=2;}}; ए ए; a.f(); अदालत
A
Compile error संकलन त्रुटि
B
12 12
C
11 11
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.f() lvalue: x=1. A().f() rvalue: x=2. Output: 12.
व्याख्या (हिन्दी) a.f() लाभ मान: x=1. A().f() प्रतिमूल्य: x=2. आउटपुट: 12.
1354
EN + हिं
GB What is the output: class A{public:A()=delete;}; A a;
IN आउटपुट क्या है: class A{public:A()=delete;}; ए ए;
A
Compile error संकलन त्रुटि
B
Works काम करता है
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A()=delete; A a tries to call it. Compile error.
व्याख्या (हिन्दी) ए()=हटाएं; ए इसे कॉल करने का प्रयास करता है। संकलन त्रुटि.
1355
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} auto operator<=>(const A&)const=default;}; A a(3),b(5); cout<<(a
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} ऑटो ऑपरेटर(const A&)const=default;}; ए ए(3),बी(5); अदालत
A
10 10
B
01 01
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3<5=1; 3==5=0. Output: 10.
व्याख्या (हिन्दी) 3
1356
EN + हिं
GB What is the output: class A{public:int x=0; void inc(int n=1){x+=n;}}; A a; a.inc(); a.inc(5); cout<
IN आउटपुट क्या है: class A{public:int x=0; void inc(int n=1){x+=n;}}; ए ए; a.inc(); ए.इंक(5); अदालत
A
6 6
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) inc()=x+=1=1; inc(5)=x+=5=6. Output: 6.
व्याख्या (हिन्दी) inc()=x+=1=1; inc(5)=x+=5=6. आउटपुट: 6.
1357
EN + हिं
GB What is the output: class A{public:int x=0; explicit operator bool()const{return x!=0;}}; A a; a.x=5; if(a) cout<<'Y'; else cout<<'N';
IN आउटपुट क्या है: class A{public:int x=0; स्पष्ट ऑपरेटर बूल() स्थिरांक {वापसी x!=0;}}; ए ए; a.x=5; यदि (ए) कोउट
A
Y वाई
B
N एन
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=5!=0=true. if(a)=Y. Output: Y.
व्याख्या (हिन्दी) a.x=5!=0=सत्य. यदि(ए)=वाई. आउटपुट: वाई.
1358
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.
1359
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(const A& o):x(o.x*2){}}; A a(3); A b(a); A c(b); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A(const A& o):x(o.x*2){}}; ए ए(3); ए बी(ए); ए सी(बी); अदालत
A
3612 3612
B
336 336
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=3; b.x=3*2=6; c.x=6*2=12. Output: 3612.
व्याख्या (हिन्दी) a.x=3; b.x=3*2=6; c.x=6*2=12. आउटपुट: 3612.
1360
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=5; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: A&operator=(int v){x=v;return *this;} int get()const{return x;}}; ए ए; ए=5; अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=5: operator=(5): x=5. Output: 5.
व्याख्या (हिन्दी) a=5: ऑपरेटर=(5): x=5. आउटपुट: 5.
1361
EN + हिं
GB What is the output: class A{public:~A(){cout<<'X';} A()=default; A(A&&)=default;}; A f(){return A();} A a=f(); cout<<'Y';
IN आउटपुट क्या है: क्लास ए{पब्लिक:~ए(){काउट
A
XY XY
B
YX YX
C
Y वाई
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++17 mandatory elision: no move/copy needed. a created directly. At end: ~a prints X. But cout<<'Y' first. Output: YX.
व्याख्या (हिन्दी) C++17 अनिवार्य एलिज़न: कोई स्थानांतरण/प्रतिलिपि की आवश्यकता नहीं है। एक सीधे बनाया गया. अंत में: ~a X प्रिंट करता है। लेकिन कॉउट
1362
EN + हिं
GB What is the output: class A{public:int x; A():x(0){} A(int v):x(v){}}; A arr[3]={1,2,3}; cout<
IN आउटपुट क्या है: class A{public:int x; A():x(0){} A(int v):x(v){}}; एक गिरफ्तारी[3]={1,2,3}; अदालत
A
13 13
B
31 31
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) arr[0].x=1, arr[2].x=3. Output: 13.
व्याख्या (हिन्दी) गिरफ्तारी[0].x=1, गिरफ्तारी[2].x=3. आउटपुट: 13.
1363
EN + हिं
GB What is the output: class A{public:int x=0; ~A(){x=-1;} int getAfterDtor(){return x;}}; A *p=new A; delete p; // p->getAfterDtor() would be UB
IN आउटपुट क्या है: class A{public:int x=0; ~A(){x=-1;} int getAfterDtor(){return x;}}; ए *पी=नया ए; पी हटाएं; // p->getAfterDtor() यूबी होगा
A
Undefined behavior अपरिभाषित व्यवहार
C
-1 -1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Accessing deleted object is UB.
व्याख्या (हिन्दी) हटाए गए ऑब्जेक्ट तक पहुंच यूबी है।
1364
EN + हिं
GB What is the output: class A{public:int x; constexpr A(int v):x(v*v){}}; constexpr A a(4); cout<
IN आउटपुट क्या है: class A{public:int x; constexpr A(int v):x(v*v){}}; constexpr ए ए(4); अदालत
A
16 16
B
4 4
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) constexpr A(4): x=16. Output: 16.
व्याख्या (हिन्दी) constexpr A(4): x=16. आउटपुट: 16.
1365
EN + हिं
GB What is the output: class A{public:int x=0,y=0; A()=default; A(int a,int b):x(a),y(b){}}; A a{3,4}; cout<
IN आउटपुट क्या है: class A{public:int x=0,y=0; ए()=डिफ़ॉल्ट; A(int a,int b):x(a),y(b){}}; ए ए{3,4}; अदालत
A
34 34
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
00 00
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A has user-provided constructor so not aggregate; A a{3,4} calls A(int,int). Output: 34.
व्याख्या (हिन्दी) A के पास उपयोगकर्ता द्वारा प्रदत्त कंस्ट्रक्टर है इसलिए समग्र नहीं; A a{3,4} A(int,int) को कॉल करता है। आउटपुट: 34.
1351–1365 of 1915