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
46
EN + हिं
GB What is the output: class A{int x=5; public: A& setX(int v){x=v; return *this;} int getX()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: A& setX(int v){x=v; वापसी *यह;} int getX() स्थिरांक{वापसी x;}}; ए ए; अदालत
A
20 20
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) setX(10) returns *this; setX(20) sets x=20; getX()=20. Output: 20.
व्याख्या (हिन्दी) setX(10) रिटर्न *यह; setX(20) सेट x=20; getX()=20. आउटपुट: 20.
47
EN + हिं
GB What is the output: class A{static int n; public: A(){n++;} ~A(){n (1, 6, 82, 12, 4, 'What is the output: class A{int x; public: A(int v):x(v){} void print()const{cout<
IN आउटपुट क्या है: class A{static int n; सार्वजनिक: A(){n++;} ~A(){n (1, 6, 82, 12, 4, 'आउटपुट क्या है: क्लास ए {इंट एक्स; पब्लिक: ए (इंट वी): एक्स (वी) {} शून्य प्रिंट() कॉन्स्ट {काउट
A
Forward-declared impl pointer hides implementation details अग्रेषित-घोषित इम्प्ल सूचक कार्यान्वयन विवरण छुपाता है
B
A void pointer एक शून्य सूचक
C
A smart pointer एक स्मार्ट सूचक
D
A raw pointer एक कच्चा सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) class A{struct Impl; unique_ptr pImpl;}; — Impl defined only in .cpp.
व्याख्या (हिन्दी) कक्षा ए {struct Impl; अद्वितीय_ptr pImpl;}; - Impl को केवल .cpp में परिभाषित किया गया है।
48
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
99 99
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f(a) passes by value; f modifies its own copy x=99; prints 99. Output: 99.
व्याख्या (हिन्दी) एफ(ए) मूल्य से गुजरता है; f अपनी प्रतिलिपि x=99 को संशोधित करता है; प्रिंट 99. आउटपुट: 99.
49
EN + हिं
GB What is 'opaque pointer' (pimpl)?
IN 'अपारदर्शी सूचक' (पिंपल) क्या है?
A
Forward-declared impl pointer hides implementation details अग्रेषित-घोषित इम्प्ल सूचक कार्यान्वयन विवरण छुपाता है
B
A void pointer एक शून्य सूचक
C
A smart pointer एक स्मार्ट सूचक
D
A raw pointer एक कच्चा सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) class A{struct Impl; unique_ptr pImpl;}; — Impl defined only in .cpp.
व्याख्या (हिन्दी) कक्षा ए {struct Impl; अद्वितीय_ptr pImpl;}; - Impl को केवल .cpp में परिभाषित किया गया है।
50
EN + हिं
GB What is the output: class A{int x=0; public: void set(int v){x=v;} auto get()const{return x;}}; A a; a.set(7); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void set(int v){x=v;} auto get()const{return x;}}; ए ए; ए.सेट(7); अदालत
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) get() returns x=7. Output: 7.
व्याख्या (हिन्दी) get() x=7 लौटाता है। आउटपुट: 7.
51
EN + हिं
GB What is the output: class A{int x=0; public: int& operator[](int i){x=i; return x;}}; A a; a[5]; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int& ऑपरेटर[](int i){x=i; वापसी x;}}; ए ए; ए[5]; अदालत
A
3 3
B
5 5
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a[5]: x=5. a[3]: x=3, returns ref. cout<<3. Output: 3.
व्याख्या (हिन्दी) ए[5]: x=5. a[3]: x=3, रिटर्न रेफरी। अदालत
52
EN + हिं
GB What is 'accessor' pattern?
IN 'एक्सेसर' पैटर्न क्या है?
A
get/set functions controlling access to private data निजी डेटा तक पहुंच को नियंत्रित करने वाले फ़ंक्शन प्राप्त/सेट करें
B
Same as property संपत्ति के समान
C
A design pattern एक डिज़ाइन पैटर्न
D
A C++20 feature एक C++20 सुविधा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Accessors (getters/setters) provide controlled access to private members.
व्याख्या (हिन्दी) एक्सेसर्स (गेटर्स/सेटर्स) निजी सदस्यों को नियंत्रित पहुंच प्रदान करते हैं।
53
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} int operator()(int y)const{return x+y;}}; A a(10); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} int ऑपरेटर()(int y)const{return x+y;}}; ए ए(10); अदालत
A
15 15
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 10+5=15. Output: 15.
व्याख्या (हिन्दी) 10+5=15. आउटपुट: 15.
54
EN + हिं
GB What is the output: class A{int x=1,y=2,z=3; public: tuple getAll()const{return {x,y,z};}}; A a; auto [x,y,z]=a.getAll(); cout<
IN आउटपुट क्या है: class A{int x=1,y=2,z=3; सार्वजनिक: टुपल getAll() स्थिरांक {वापसी {x,y,z};}}; ए ए; ऑटो [x,y,z]=a.getAll(); अदालत
A
123 123
B
321 321
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=1,y=2,z=3. Output: 123.
व्याख्या (हिन्दी) x=1,y=2,z=3. आउटपुट: 123.
55
EN + हिं
GB What is the output: class A{int x=0; public: void f(){x=42;} int get()const{return x;}}; const A a; a.f();
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void f(){x=42;} int get()const{return x;}}; स्थिरांक ए ए; a.f();
A
Compile error संकलन त्रुटि
B
42 42
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Cannot call non-const f() on const a. Compile error.
व्याख्या (हिन्दी) स्थिरांक a पर गैर-स्थिरांक f() को कॉल नहीं किया जा सकता। संकलन त्रुटि.
56
EN + हिं
GB What is the output: class A{int x=0; public: void set(int v){x=v;} int get()const{return x;} void reset(){x=0;}}; A a; a.set(5); a.reset(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: शून्य सेट (int v) {x = v;} int get() स्थिरांक {वापसी x;} शून्य रीसेट() {x = 0;}}; ए ए; ए.सेट(5); ए.रीसेट(); अदालत
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x set to 5, then reset to 0. Output: 0.
व्याख्या (हिन्दी) x को 5 पर सेट करें, फिर 0 पर रीसेट करें। आउटपुट: 0।
57
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} A(const A& o):x(o.x){} A& operator=(const A& o){x=o.x;return *this;}}; A a(3); A b=a; b=A(7); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} A(const A& o):x(o.x){} A& ऑपरेटर=(const A& o){x=o.x;return *this;}}; ए ए(3); ए बी=ए; बी=ए(7); अदालत
A
37 37
B
33 33
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b=A(7): assign x=7 to b. a.x=3. Output: 37.
व्याख्या (हिन्दी) b=A(7): b को x=7 असाइन करें। a.x=3. आउटपुट: 37.
58
EN + हिं
GB What is the output: class A{int x=5; public: int get()const{return x;} void set(int v){x=v;}}; A *p=new A; p->set(10); cout<get(); delete p;
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: int get()const{return x;} void set(int v){x=v;}}; ए *पी=नया ए; पी->सेट(10); अदालत
A
10 10
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->set(10): x=10. p->get()=10. Output: 10.
व्याख्या (हिन्दी) p->सेट(10): x=10. पी->प्राप्त करें()=10। आउटपुट: 10.
59
EN + हिं
GB What is 'class invariant enforcement'?
IN 'वर्ग अपरिवर्तनीय प्रवर्तन' क्या है?
A
Setter validates input to maintain invariant सेटर अपरिवर्तनीय बनाए रखने के लिए इनपुट को मान्य करता है
B
Constructor only केवल कंस्ट्रक्टर
C
Runtime assertion रनटाइम दावा
D
Exception only केवल अपवाद
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Invariant: balance>=0. Setter: if(v<0) throw; ensures invariant holds for all valid operations.
व्याख्या (हिन्दी) अपरिवर्तनीय: संतुलन>=0. सेटर: यदि(v
60
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; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: ए एवं ऑपरेटर
A
6 6
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=0+1+2+3=6. Output: 6.
व्याख्या (हिन्दी) x=0+1+2+3=6. आउटपुट: 6.
46–60 of 107