OOP Using C++ — MCQ Practice

Hindi aur English dono mein practice karo — click karo answer check karne ke liye

📚 106 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
106 questions
46
EN + हिं
GB What is the output: class A{public:int v; A(int x):v(x){} A operator+(const A& o){return A(v+o.v);}}; A a(3),b(4); cout<<(a+b).v;
IN आउटपुट क्या है: class A{public:int v; A(int x):v(x){} A ऑपरेटर+(const A& o){return A(v+o.v);}}; ए ए(3),बी(4); अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
47
EN + हिं
GB What is 'non-static data member initializer'?
IN 'नॉन-स्टैटिक डेटा मेंबर इनिशियलाइज़र' क्या है?
A
int x=5; inside class body — default member value int x=5; क्लास बॉडी के अंदर - डिफ़ॉल्ट सदस्य मान
B
Static member init स्टेटिक सदस्य init
C
Const member कॉन्स्ट सदस्य
D
Constructor only केवल कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++11: class A{int x=5;}; x is initialized to 5 if constructor doesn't override it.
व्याख्या (हिन्दी) सी++11: कक्षा ए{int x=5;}; यदि कंस्ट्रक्टर इसे ओवरराइड नहीं करता है तो x को 5 से प्रारंभ किया जाता है।
48
EN + हिं
GB What is the output: class A{public:int x=1,y=2,z=3; int sum(){return x+y+z;}}; A a; a.x=10; cout<
IN आउटपुट क्या है: class A{public:int x=1,y=2,z=3; int sum(){रिटर्न x+y+z;}}; ए ए; a.x=10; अदालत
A
15 15
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 10+2+3=15. Output: 15.
व्याख्या (हिन्दी) 10+2+3=15. आउटपुट: 15.
49
EN + हिं
GB What is 'this pointer' type?
IN 'यह सूचक' प्रकार क्या है?
A
T* const (in non-const member) or const T* const (in const member) T* const (गैर-const सदस्य में) या const T* const (const सदस्य में)
B
T* always टी* हमेशा
C
const T* always स्थिरांक टी* हमेशा
D
void* खालीपन*
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) In non-const: this is T* const; in const member: const T* const.
व्याख्या (हिन्दी) गैर-स्थिरांक में: यह T* स्थिरांक है; स्थिरांक सदस्य में: स्थिरांक टी* स्थिरांक।
50
EN + हिं
GB What is the output: class A{int x; public: explicit A(int v):x(v){} int get()const{return x;}}; A a(5); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: स्पष्ट A(int v):x(v){} int get()const{return x;}}; ए ए(5); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Explicit ctor sets x=5. get()=5. Output: 5.
व्याख्या (हिन्दी) स्पष्ट ctor सेट x=5. प्राप्त करें()=5. आउटपुट: 5.
51
EN + हिं
GB What is 'std::move' on class object?
IN क्लास ऑब्जेक्ट पर 'std::move' क्या है?
A
Casts to rvalue reference, enabling move constructor मूव कंस्ट्रक्टर को सक्षम करते हुए, संदर्भ को प्रतिस्थापित करने के लिए कास्ट किया जाता है
B
Copies the object ऑब्जेक्ट की प्रतिलिपि बनाता है
C
Deletes the object ऑब्जेक्ट को हटा देता है
D
Makes object const ऑब्जेक्ट स्थिरांक बनाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) std::move(x) is static_cast(x); enables move semantics without copying.
व्याख्या (हिन्दी) std::move(x) static_cast(x) है; नकल किए बिना शब्दार्थ को स्थानांतरित करने में सक्षम बनाता है।
52
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(A&& o):x(o.x*2){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(o.x*2){o.x=0;}}; ए ए(5); ए बी = चाल (ए); अदालत
A
010 010
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.x=5*2=10, a.x=0. Output: 010.
व्याख्या (हिन्दी) b.x=5*2=10, a.x=0. आउटपुट: 010.
53
EN + हिं
GB What is the output: class A{int x=0; public: void f()const{cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: शून्य f()const{cout
A
50 50
B
05 05
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.f() non-const: x=5,print 5. ca.f() const: print x=0. Output: 50.
व्याख्या (हिन्दी) a.f() गैर-स्थिरांक: x=5,प्रिंट 5. ca.f() स्थिरांक: प्रिंट x=0. आउटपुट: 50.
54
EN + हिं
GB What is 'CRTP for static polymorphism'?
IN 'स्थैतिक बहुरूपता के लिए सीआरटीपी' क्या है?
A
Base<Derived>: call derived method without virtual आधार: वर्चुअल के बिना व्युत्पन्न विधि को कॉल करें
B
Runtime dispatch रनटाइम प्रेषण
C
Multiple inheritance एकाधिक वंशानुक्रम
D
Abstract class सार वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) CRTP: static_cast(this)->impl() resolves at compile time; zero virtual overhead.
व्याख्या (हिन्दी) सीआरटीपी: static_cast(this)->impl() संकलन समय पर हल हो जाता है; शून्य वर्चुअल ओवरहेड.
55
EN + हिं
GB What is the output: class Counter{int n=0; public: Counter& operator++(){n++;return *this;} int get()const{return n;}}; Counter c; ++c;++c;++c; cout<
IN आउटपुट क्या है: क्लास काउंटर{int n=0; सार्वजनिक: काउंटर और ऑपरेटर++(){n++;रिटर्न *यह;} int get()const{रिटर्न n;}}; काउंटर सी; ++सी;++सी;++सी; अदालत
A
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) n incremented 3 times. get()=3. Output: 3.
व्याख्या (हिन्दी) n 3 गुना बढ़ाया गया। प्राप्त करें()=3. आउटपुट: 3.
56
EN + हिं
GB What is the output: class A{public:A(){cout<<'C';} A(const A&){cout<<'P';} A(A&&){cout<<'M';} ~A(){cout<<'D';}}; A a=A();
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
C सी
B
CD सीडी
C
CM सेमी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++17 mandatory elision: A() creates directly into a. Ctor prints C; dtor at end prints D. Output: CD.
व्याख्या (हिन्दी) C++17 अनिवार्य एलिज़न: A() सीधे a में बनता है। सीटीओआर सी प्रिंट करता है; अंत में डीटीओआर डी प्रिंट करता है। आउटपुट: सीडी।
57
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} bool operator<(const A& o)const{return x
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} बूल ऑपरेटर
A
10 10
B
01 01
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3<5=1, 5<3=0. Output: 10.
व्याख्या (हिन्दी) 3
58
EN + हिं
GB What is the output: class A{public:int x=0; void f(int v){x=v;} auto g(){return [this]{return x;};}}; A a; a.f(42); cout<
IN आउटपुट क्या है: class A{public:int x=0; शून्य f(int v){x=v;} ऑटो g(){वापसी [यह]{वापसी x;};}}; ए ए; ए.एफ(42); अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Lambda captures this; returns x=42. Output: 42.
व्याख्या (हिन्दी) लैम्ब्डा ने इसे पकड़ लिया; x=42 लौटाता है। आउटपुट: 42.
59
EN + हिं
GB What is 'object layout' in C++?
IN C++ में 'ऑब्जेक्ट लेआउट' क्या है?
A
Order of data members in memory (plus padding, vptr) मेमोरी में डेटा सदस्यों का क्रम (प्लस पैडिंग, वीपीटीआर)
B
Virtual table only केवल वर्चुअल टेबल
C
Heap layout ढेर लेआउट
D
Stack layout ढेर लेआउट
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Object layout: members stored in declaration order, with alignment padding; virtual classes add vptr.
व्याख्या (हिन्दी) ऑब्जेक्ट लेआउट: सदस्यों को संरेखण पैडिंग के साथ घोषणा क्रम में संग्रहीत किया जाता है; आभासी कक्षाएँ vptr जोड़ती हैं।
60
EN + हिं
GB What is the output: class A{public:int x=5; operator bool()const{return x!=0;}}; A a; if(a) cout<<'Y'; else cout<<'N';
IN आउटपुट क्या है: class A{public:int x=5; ऑपरेटर बूल() स्थिरांक {वापसी x!=0;}}; ए ए; यदि (ए) कोउट
A
Y वाई
B
N एन
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=5!=0=true. if(a) executes. Output: Y.
व्याख्या (हिन्दी) a.x=5!=0=सत्य. यदि (ए) निष्पादित करता है। आउटपुट: वाई.
46–60 of 106