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
76
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){cout<<'C';} ~A(){cout<<'D';} A(A&&o):x(o.x){o.x=0;cout<<'M';}}; A f(){return A(5);} A a=f(); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){cout
A
C5 सी 5
B
CM5 सीएम5
C
CCD5 सीसीडी5
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++17 mandatory elision: only one C, no move. a.x=5. Output: C5D (D at scope end, but question asks output before scope end: C5).
व्याख्या (हिन्दी) C++17 अनिवार्य एलिशन: केवल एक C, कोई चाल नहीं। a.x=5. आउटपुट: C5D (D स्कोप अंत में है, लेकिन प्रश्न स्कोप अंत से पहले आउटपुट पूछता है: C5)।
77
EN + हिं
GB What is the output: class A{public:int x=0; A(){} A(int v):x(v){} A(const A& o):x(o.x*2){}}; A a(3); A b; b=a; cout<
IN आउटपुट क्या है: class A{public:int x=0; A(){} A(int v):x(v){} A(const A& o):x(o.x*2){}}; ए ए(3); ए बी; बी=ए; अदालत
A
3 3
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b=a uses compiler-generated assignment (copies x). b.x=3. Output: 3.
व्याख्या (हिन्दी) b=a कंपाइलर-जनरेटेड असाइनमेंट (कॉपी x) का उपयोग करता है। बी.एक्स=3. आउटपुट: 3.
78
EN + हिं
GB What is the output: class A{public:int x; A():x(0){cout<<'D';} A(int v):x(v){cout<<'P';} A(const A&o):x(o.x){cout<<'C';}}; A a=5;
IN आउटपुट क्या है: class A{public:int x; A():x(0){cout
A
P पी
B
C सी
C
D डी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a=5: copy-initialization from int: A(int) called. Output: P.
व्याख्या (हिन्दी) A a=5: int से कॉपी-इनिशियलाइज़ेशन: A(int) कहा जाता है। आउटपुट: पी.
79
EN + हिं
GB What is the output: class A{public:int x; A(int v=10):x(v){} ~A(){cout<
IN आउटपुट क्या है: class A{public:int x; A(int v=10):x(v){} ~A(){cout
A
151 151
B
1510 1510
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Destructors: ~c(1),~b(5),~a(10). Output: 1510.
व्याख्या (हिन्दी) विध्वंसक: ~सी(1),~बी(5),~ए(10)। आउटपुट: 1510.
80
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A& operator=(int v){x=v;return *this;}}; A a(3); a=5; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A& ऑपरेटर=(int v){x=v;रिटर्न *यह;}}; ए ए(3); ए=5; अदालत
A
5 5
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a=5: operator=(5): x=5. Output: 5.
व्याख्या (हिन्दी) a=5: ऑपरेटर=(5): x=5. आउटपुट: 5.
81
EN + हिं
GB What is the output: class A{public:string s; A(string t):s(move(t)){}}; A a("hello"); cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:स्ट्रिंग एस; ए(स्ट्रिंग टी):एस(मूव(टी)){}}; ए ए('हैलो'); अदालत
A
hello नमस्ते
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) s initialized by moving t. a.s="hello". Output: hello.
व्याख्या (हिन्दी) s को t ले जाकर प्रारंभ किया गया। a.s='हैलो'। आउटपुट: नमस्ते.
82
EN + हिं
GB What is the output: class A{public:int x,y; A(int a,int b):x(a),y(b){} A(pairp):A(p.first,p.second){}}; A a({3,4}); cout<
IN आउटपुट क्या है: class A{public:int x,y; A(int a,int b):x(a),y(b){} A(pairp):A(p.first,p.Second){}}; ए ए({3,4}); अदालत
A
34 34
B
43 43
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Delegates to A(3,4). x=3,y=4. Output: 34.
व्याख्या (हिन्दी) ए(3,4) को प्रतिनिधि। x=3,y=4. आउटपुट: 34.
83
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(const A& o)=delete;}; A f(){return A(5);} A a=f(); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A(const A& o)=delete;}; A f(){वापसी A(5);} A a=f(); अदालत
A
5 5
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++17 mandatory elision doesn't require copy ctor. Output: 5.
व्याख्या (हिन्दी) C++17 अनिवार्य एलिज़न को कॉपी ctor की आवश्यकता नहीं है। आउटपुट: 5.
84
EN + हिं
GB What is the output: class A{public:int x=0; ~A(){x=-1;} void print(){cout<x=5; p->print(); delete p; cout<x;
IN आउटपुट क्या है: class A{public:int x=0; ~A(){x=-1;} void print(){coutprint(); पी हटाएं; अदालत
A
5 then UB 5 फिर यूबी
B
Compile error संकलन त्रुटि
C
5-1 5-1
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) print()=5; after delete: p->x is UB. Output: 5 then UB.
व्याख्या (हिन्दी) प्रिंट()=5; हटाने के बाद: p->x UB है। आउटपुट: 5 फिर यूबी।
85
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){cout
A
123-3-2-1 123-3-2-1
B
123321 123321
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructed: 1,2,3. Destroyed reverse: -3,-2,-1. Output: 123-3-2-1.
व्याख्या (हिन्दी) निर्मित: 1,2,3. नष्ट उल्टा:-3,-2,-1. आउटपुट: 123-3-2-1.
86
EN + हिं
87
EN + हिं
GB What is the output: class A{int* p; public:A(int v):p(new int(v)){} ~A(){delete p;} A(const A& o):p(new int(*o.p)){} int get()const{return *p;}}; A a(5); A b=a; *b.p=10; cout<
IN आउटपुट क्या है: class A{int* p; सार्वजनिक:ए(int v):p(नया int(v)){} ~A(){delete p;} A(const A& o):p(new int(*o.p)){} int get()const{return *p;}}; ए ए(5); ए बी=ए; *बी.पी=10; अदालत
A
510 510
B
1010 1010
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Deep copy: b has own int. *b.p=10. a unchanged=5. Output: 510.
व्याख्या (हिन्दी) डीप कॉपी: बी का अपना इंट है। *बी.पी=10. एक अपरिवर्तित=5. आउटपुट: 510.
88
EN + हिं
GB What is the output: class A{public:int x; A():x(0){cout<<'0';} A(int v):x(v){cout<<'I';} ~A(){cout<<'D';}}; A arr[3];
IN आउटपुट क्या है: class A{public:int x; A():x(0){cout
A
000DDD 000डीडीडी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
0I0DDD 0आई0डीडीडी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3 default ctors: 000. 3 dtors: DDD. Output: 000DDD.
व्याख्या (हिन्दी) 3 डिफ़ॉल्ट ctors: 000. 3 dtors: DDD. आउटपुट: 000DDD.
89
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A operator+(const A& o){return A(x+o.x);} A& operator+=(const A& o){x+=o.x;return *this;}}; A a(3),b(4); a+=b; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A ऑपरेटर+(const A& o){रिटर्न A(x+o.x);} A& ऑपरेटर+=(const A& o){x+=o.x;रिटर्न *यह;}}; ए ए(3),बी(4); ए+=बी; अदालत
A
7 7
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=3+4=7. Output: 7.
व्याख्या (हिन्दी) a.x=3+4=7. आउटपुट: 7.
90
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(A&& o):x(exchange(o.x,0)){}}; A a(5); A b=move(a); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A(A&& o):x(exchange(o.x,0)){}}; ए ए(5); ए बी = चाल (ए); अदालत
A
05 05
B
50 50
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) exchange(a.x,0) returns 5, sets a.x=0. b.x=5. Output: 05.
व्याख्या (हिन्दी) एक्सचेंज(a.x,0) 5 लौटाता है, a.x=0 सेट करता है। बी.एक्स=5. आउटपुट: 05.
76–90 of 107