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
16
EN + हिं
GB What is 'aggregate initialization'?
IN 'समग्र आरंभीकरण' क्या है?
A
Initializing aggregate types with brace-enclosed list ब्रेस-संलग्न सूची के साथ समुच्चय प्रकारों को प्रारंभ करना
B
Initializing arrays only केवल आरंभिक सरणियाँ
C
Virtual class initialization वर्चुअल क्लास आरंभीकरण
D
Constructor with multiple params एकाधिक पैरामीटर वाला कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Aggregates (classes with no user-defined constructors, etc.) can be initialized with {val1, val2, ...}.
व्याख्या (हिन्दी) एग्रीगेट्स (बिना उपयोगकर्ता-परिभाषित कंस्ट्रक्टर वाली कक्षाएं, आदि) को {val1, val2, ...} के साथ प्रारंभ किया जा सकता है।
17
EN + हिं
GB What is the output: class A{public: int x=10; int f() const {return x;}}; const A a; cout<
IN आउटपुट क्या है: class A{public: int x=10; int f() स्थिरांक {वापसी x;}}; स्थिरांक ए ए; अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) const object can only call const member functions. f() is const and returns x=10.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट केवल कॉन्स्ट सदस्य फ़ंक्शंस को कॉल कर सकता है। f() स्थिरांक है और x=10 लौटाता है।
18
EN + हिं
GB What is 'explicit' constructor?
IN 'स्पष्ट' कंस्ट्रक्टर क्या है?
A
Prevents implicit conversion of constructor argument कंस्ट्रक्टर तर्क के अंतर्निहित रूपांतरण को रोकता है
B
Makes constructor public कंस्ट्रक्टर को सार्वजनिक बनाता है
C
Forces inline expansion इनलाइन विस्तार को बल देता है
D
Deletes copy constructor कॉपी कंस्ट्रक्टर को हटाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) explicit prevents the constructor from being used in implicit conversions or copy-initialization.
व्याख्या (हिन्दी) स्पष्ट कन्स्ट्रक्टर को अंतर्निहित रूपांतरण या प्रतिलिपि-प्रारंभिकरण में उपयोग करने से रोकता है।
19
EN + हिं
GB What is the output: class A{public: static void f(){cout<<'S';} void g(){cout<<'G';}}; A::f(); A a; a.g();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: स्थिर शून्य एफ() {काउट
A
SG एसजी
B
GS जी एस
C
Compile error संकलन त्रुटि
D
SS एसएस
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f() calls static f, prints S. a.g() calls instance g, prints G. Output: SG.
व्याख्या (हिन्दी) A::f() स्टेटिक f को कॉल करता है, S को प्रिंट करता है। a.g() इंस्टेंस g को कॉल करता है, G को प्रिंट करता है। आउटपुट: SG।
20
EN + हिं
GB What is the output: class A{public: int x; A(int v=0):x(v){}}; A a=5; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v=0):x(v){}}; ए ए=5; अदालत
A
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a=5 uses implicit conversion (copy-initialization): calls A(5), x=5. Output: 5.
व्याख्या (हिन्दी) A a=5 अंतर्निहित रूपांतरण (कॉपी-इनिशियलाइज़ेशन) का उपयोग करता है: A(5), x=5 को कॉल करता है। आउटपुट: 5.
21
EN + हिं
GB What is a 'nested class' in C++?
IN C++ में 'नेस्टेड क्लास' क्या है?
A
A class defined inside another class एक वर्ग को दूसरे वर्ग के अंदर परिभाषित किया गया है
B
A class with multiple inheritance एकाधिक वंशानुक्रम वाला एक वर्ग
C
A template class एक टेम्पलेट क्लास
D
Abstract class सार वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A nested class is defined within the scope of an enclosing class.
व्याख्या (हिन्दी) एक नेस्टेड वर्ग को एक संलग्न वर्ग के दायरे में परिभाषित किया गया है।
22
EN + हिं
GB What is the output: class A{public: ~A(){cout<<'D';}}; A *p=new A; delete p;
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: ~ ए() {काउट
A
D डी
B
Nothing कुछ नहीं
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete p calls destructor, which prints D.
व्याख्या (हिन्दी) डिलीट पी कॉल डिस्ट्रक्टर, जो डी प्रिंट करता है।
23
EN + हिं
GB What is 'method chaining' in C++?
IN C++ में 'मेथड चेनिंग' क्या है?
A
Returning *this from member functions to chain calls *इसे सदस्य फ़ंक्शंस से चेन कॉल पर लौटाना
B
Calling multiple methods sequentially एकाधिक विधियों को क्रमिक रूप से कॉल करना
C
Virtual method dispatch आभासी विधि प्रेषण
D
Template method pattern टेम्पलेट विधि पैटर्न
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Returning *this from methods enables: obj.setX(1).setY(2).setZ(3) style chaining.
व्याख्या (हिन्दी) तरीकों से इसे वापस करने से सक्षम होता है: obj.setX(1).setY(2).setZ(3) स्टाइल चेनिंग।
24
EN + हिं
GB What is the output: struct A{int x,y; A(int a,int b):x(a),y(b){}}; A a{3,4}; cout<
IN आउटपुट क्या है: struct A{int x,y; A(int a,int b):x(a),y(b){}}; ए ए{3,4}; अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a{3,4} calls constructor: x=3,y=4. x+y=7. Output: 7.
व्याख्या (हिन्दी) A a{3,4} कंस्ट्रक्टर को कॉल करता है: x=3,y=4। x+y=7. आउटपुट: 7.
25
EN + हिं
GB What is 'CRTP' (Curiously Recurring Template Pattern)?
IN 'सीआरटीपी' (क्यूरियसली रिकरिंग टेम्पलेट पैटर्न) क्या है?
A
Base class template parameterized with derived class बेस क्लास टेम्पलेट को व्युत्पन्न क्लास के साथ पैरामीटरयुक्त किया गया है
B
Recursive template instantiation पुनरावर्ती टेम्पलेट इन्स्टेन्शियशन
C
Multiple inheritance pattern एकाधिक वंशानुक्रम पैटर्न
D
Virtual function replacement वर्चुअल फ़ंक्शन प्रतिस्थापन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) CRTP: template class Base{}; class Derived: public Base{}; enables static polymorphism.
व्याख्या (हिन्दी) सीआरटीपी: टेम्पलेट क्लास बेस{}; वर्ग व्युत्पन्न: सार्वजनिक आधार{}; स्थैतिक बहुरूपता को सक्षम बनाता है।
26
EN + हिं
GB What is the output: class A{public: int x=5; int& f(){return x;}}; A a; a.f()=10; cout<
IN आउटपुट क्या है: class A{public: int x=5; int& f(){रिटर्न x;}}; ए ए; a.f()=10; अदालत
A
5 5
B
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() returns reference to x. Assigning 10 to it sets x=10. Output: 10.
व्याख्या (हिन्दी) f() x का संदर्भ लौटाता है। इसमें 10 निर्दिष्ट करने पर x=10 सेट हो जाता है। आउटपुट: 10.
27
EN + हिं
GB What is the output: class A{int x=0; public: void inc(){x++;} int get()const{return x;}}; A a,b=a; a.inc(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void inc(){x++;} int get()const{return x;}}; ए ए,बी=ए; a.inc(); अदालत
A
10 10
B
11 11
C
01 01
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b is a copy of a (x=0). a.inc() makes a.x=1. b.x stays 0. Output: 10.
व्याख्या (हिन्दी) b, a (x=0) की एक प्रति है। a.inc() a.x=1 बनाता है। b.x 0 रहता है। आउटपुट: 10।
28
EN + हिं
GB What is 'type punning' in C++?
IN C++ में 'टाइप पनिंग' क्या है?
A
Reinterpreting memory as different type स्मृति को भिन्न प्रकार के रूप में पुनःव्याख्या करना
B
Type aliasing with typedef टाइपडिफ के साथ अलियासिंग टाइप करें
C
Template specialization टेम्पलेट विशेषज्ञता
D
Dynamic casting गतिशील कास्टिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Type punning reads object representation as a different type, often via union or memcpy, sometimes undefined behavior with pointer casts.
व्याख्या (हिन्दी) टाइप पनिंग ऑब्जेक्ट प्रतिनिधित्व को एक अलग प्रकार के रूप में पढ़ता है, अक्सर यूनियन या मेम्सीपी के माध्यम से, कभी-कभी पॉइंटर कास्ट के साथ अपरिभाषित व्यवहार।
29
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';}}; class B:public A{public: void f()override{cout<<'B';}}; A*p=new B; p->f(); delete p;
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual dispatch: p is A* pointing to B object. p->f() calls B::f() via vtable. Output: B.
व्याख्या (हिन्दी) आभासी प्रेषण: p, A* है जो B ऑब्जेक्ट की ओर इशारा करता है। p->f() vtable के माध्यम से B::f() को कॉल करता है। आउटपुट: बी.
30
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';} A(const A&){cout<<'C';}}; A f(){return A();} A a=f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
A
B
AC ए.सी
C
ACC एसीसी
D
AA
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) RVO/copy elision (mandatory in C++17 for prvalues) eliminates copies; only one constructor call. Output: A.
व्याख्या (हिन्दी) आरवीओ/कॉपी एलिज़न (प्रचलन के लिए C++17 में अनिवार्य) प्रतियों को समाप्त करता है; केवल एक कंस्ट्रक्टर कॉल। आउटपुट: ए.
16–30 of 106