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
1
EN + हिं
GB What is the output: class A{public: int x=5;}; A a; cout<
IN आउटपुट क्या है: class A{public: int x=5;}; ए ए; अदालत
A
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) In-class member initializer sets x=5. Output: 5.
व्याख्या (हिन्दी) इन-क्लास सदस्य इनिशियलाइज़र x=5 सेट करता है। आउटपुट: 5.
2
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} int get(){return x;}}; A a(10); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} int get(){return x;}}; ए ए(10); अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor initializes x=10 via member initializer list. get() returns 10.
व्याख्या (हिन्दी) कंस्ट्रक्टर सदस्य इनिशियलाइज़र सूची के माध्यम से x=10 को इनिशियलाइज़ करता है। get() रिटर्न 10।
3
EN + हिं
GB What is 'this' pointer?
IN 'यह' सूचक क्या है?
A
Pointer to current object instance वर्तमान वस्तु उदाहरण के लिए सूचक
B
Pointer to base class बेस क्लास का सूचक
C
Global pointer वैश्विक सूचक
D
Pointer to member function सदस्य फ़ंक्शन के लिए सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 'this' is an implicit pointer available inside non-static member functions pointing to the current object.
व्याख्या (हिन्दी) 'यह' एक अंतर्निहित सूचक है जो गैर-स्थैतिक सदस्य फ़ंक्शंस के अंदर उपलब्ध है जो वर्तमान ऑब्जेक्ट की ओर इशारा करता है।
4
EN + हिं
GB What is the output: class A{public: static int x; int y;}; int A::x=5; A a; a.y=10; cout<
IN आउटपुट क्या है: वर्ग ए {सार्वजनिक: स्थिर int x; int y;}; int A::x=5; ए ए; a.y=10; अदालत
A
510 510
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::x=5 (static, class-wide). a.y=10 (instance). Output: 510.
व्याख्या (हिन्दी) A::x=5 (स्थैतिक, वर्ग-व्यापी)। a.y=10 (उदाहरण). आउटपुट: 510.
5
EN + हिं
GB What is a 'friend function'?
IN 'मित्र फ़ंक्शन' क्या है?
A
Function with access to private/protected members निजी/संरक्षित सदस्यों तक पहुंच के साथ कार्य
B
A member function एक सदस्य समारोह
C
A virtual function एक आभासी कार्य
D
A static function एक स्थिर कार्य
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A friend function declared inside a class can access its private and protected members.
व्याख्या (हिन्दी) किसी क्लास के अंदर घोषित मित्र फ़ंक्शन अपने निजी और संरक्षित सदस्यों तक पहुंच सकता है।
6
EN + हिं
GB What is the output: class A{public: int x; A(int v):x(v){} A(const A& a):x(a.x+1){}}; A a(5); A b=a; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v):x(v){} A(const A& a):x(a.x+1){}}; ए ए(5); ए बी=ए; अदालत
A
5 5
B
6 6
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Copy constructor called: b.x = a.x+1 = 6. Output: 6.
व्याख्या (हिन्दी) कॉपी कंस्ट्रक्टर कहा जाता है: b.x = a.x+1 = 6. आउटपुट: 6.
7
EN + हिं
GB What is 'object slicing' in C++?
IN C++ में 'ऑब्जेक्ट स्लाइसिंग' क्या है?
A
Derived object assigned to base: derived part lost व्युत्पन्न वस्तु को आधार सौंपा गया: व्युत्पन्न भाग खो गया
B
Virtual function optimization वर्चुअल फ़ंक्शन अनुकूलन
C
Memory fragmentation स्मृति विखंडन
D
Partial initialization आंशिक आरंभीकरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) When a derived class object is assigned to a base class object (by value), the derived-specific members are sliced off.
व्याख्या (हिन्दी) जब एक व्युत्पन्न वर्ग ऑब्जेक्ट को बेस क्लास ऑब्जेक्ट (मूल्य के आधार पर) सौंपा जाता है, तो व्युत्पन्न-विशिष्ट सदस्यों को काट दिया जाता है।
8
EN + हिं
GB What is the output: class A{public: int x=0; void f(){x++;}}; A a,b; a.f(); cout<
IN आउटपुट क्या है: class A{public: int x=0; शून्य f(){x++;}}; ए ए, बी; a.f(); अदालत
A
10 10
B
11 11
C
00 00
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a and b are separate instances. a.f() increments a.x to 1. b.x unchanged=0. Output: 10.
व्याख्या (हिन्दी) ए और बी अलग-अलग उदाहरण हैं। a.f() a.x को 1 तक बढ़ाता है। b.x अपरिवर्तित=0। आउटपुट: 10.
9
EN + हिं
GB What is 'operator overloading'?
IN 'ऑपरेटर ओवरलोडिंग' क्या है?
A
Defining operator behavior for user-defined types उपयोगकर्ता-परिभाषित प्रकारों के लिए ऑपरेटर व्यवहार को परिभाषित करना
B
Overriding operators at runtime रनटाइम पर ओवरराइडिंग ऑपरेटर
C
Removing standard operators मानक ऑपरेटरों को हटाना
D
Calling multiple operators एकाधिक ऑपरेटरों को कॉल करना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Operator overloading allows defining how operators work with user-defined classes.
व्याख्या (हिन्दी) ऑपरेटर ओवरलोडिंग यह परिभाषित करने की अनुमति देता है कि ऑपरेटर उपयोगकर्ता-परिभाषित कक्षाओं के साथ कैसे काम करते हैं।
10
EN + हिं
GB What is the output: class A{public: A(){cout<<'C';} ~A(){cout<<'D';}}; {A a;}
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
C सी
B
D डी
C
CD सीडी
D
DC डीसी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints C, then when block exits, destructor prints D. Output: CD.
व्याख्या (हिन्दी) कंस्ट्रक्टर सी प्रिंट करता है, फिर जब ब्लॉक बाहर निकलता है, तो डिस्ट्रक्टर डी प्रिंट करता है। आउटपुट: सीडी।
11
EN + हिं
GB What is a 'copy constructor'?
IN 'कॉपी कंस्ट्रक्टर' क्या है?
A
Constructor taking const reference to same class कंस्ट्रक्टर उसी क्लास का कॉन्स्ट रेफरेंस ले रहा है
B
Constructor for arrays सरणियों के लिए कंस्ट्रक्टर
C
Default constructor डिफ़ॉल्ट कंस्ट्रक्टर
D
Move constructor कंस्ट्रक्टर को स्थानांतरित करें
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Copy constructor: A(const A& other) — initializes a new object as a copy of another.
व्याख्या (हिन्दी) कॉपी कंस्ट्रक्टर: ए (कॉन्स्ट ए और अन्य) - एक नई वस्तु को दूसरे की प्रतिलिपि के रूप में प्रारंभ करता है।
12
EN + हिं
GB What is 'Rule of Three' in C++?
IN C++ में 'तीन का नियम' क्या है?
A
If you define destructor/copy-ctor/copy-assign, define all three यदि आप डिस्ट्रक्टर/कॉपी-क्टर/कॉपी-असाइन को परिभाषित करते हैं, तो तीनों को परिभाषित करें
B
Three constructors per class प्रति कक्षा तीन कंस्ट्रक्टर
C
Three virtual functions तीन आभासी कार्य
D
Three inheritance levels तीन वंशानुक्रम स्तर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If a class needs a user-defined destructor, copy constructor, or copy assignment, it likely needs all three.
व्याख्या (हिन्दी) यदि किसी वर्ग को उपयोगकर्ता-परिभाषित डिस्ट्रक्टर, कॉपी कंस्ट्रक्टर, या कॉपी असाइनमेंट की आवश्यकता होती है, तो उसे संभवतः इन तीनों की आवश्यकता होती है।
13
EN + हिं
GB What is the output: class A{public: int x; A():x(0){} A(int v):x(v){}}; A a; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A():x(0){} A(int v):x(v){}}; ए ए; अदालत
B
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a uses default constructor A():x(0). Output: 0.
व्याख्या (हिन्दी) A डिफ़ॉल्ट कंस्ट्रक्टर A():x(0) का उपयोग करता है। आउटपुट: 0.
14
EN + हिं
GB What is 'mutable' keyword for class members?
IN कक्षा सदस्यों के लिए 'म्यूटेबल' कीवर्ड क्या है?
A
Allows member to be modified even in const member functions कॉन्स्ट सदस्य फ़ंक्शंस में भी सदस्य को संशोधित करने की अनुमति देता है
B
Makes member public सदस्य को सार्वजनिक बनाता है
C
Makes member static सदस्य को स्थिर बनाता है
D
Prevents copy नकल रोकता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) mutable allows a data member to be modified inside const member functions.
व्याख्या (हिन्दी) म्यूटेबल एक डेटा सदस्य को कॉन्स्ट सदस्य फ़ंक्शन के अंदर संशोधित करने की अनुमति देता है।
15
EN + हिं
GB What is the output: class A{public: operator int(){return 42;}}; A a; cout<<(int)a;
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: ऑपरेटर int() {रिटर्न 42;}}; ए ए; अदालत
A
42 42
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) User-defined conversion operator returns 42. (int)a calls it. Output: 42.
व्याख्या (हिन्दी) उपयोगकर्ता-परिभाषित रूपांतरण ऑपरेटर 42 लौटाता है। (int)a इसे कॉल करता है। आउटपुट: 42.
1–15 of 106