OOP Using C++ — MCQ Practice

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

📚 1915 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
1915 questions
826
EN + हिं
GB What is the output: class A{public:int x; A(int v=5):x(v){} }; A a,b(10); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v=5):x(v){} }; ए ए,बी(10); अदालत
A
510 510
B
1010 1010
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=5(default), b.x=10. Output: 510.
व्याख्या (हिन्दी) a.x=5(डिफ़ॉल्ट), b.x=10. आउटपुट: 510.
827
EN + हिं
GB What is the output: class A{public:~A(){cout<<'D';}}; {A a; {A b;}}
IN आउटपुट क्या है: क्लास ए{पब्लिक:~ए(){काउट
A
DD डीडी
B
D डी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inner b destroyed first (D), then outer a (D). Output: DD.
व्याख्या (हिन्दी) पहले आंतरिक बी नष्ट हो गया (डी), फिर बाहरी ए (डी)। आउटपुट:डीडी.
828
EN + हिं
GB What is the output: class A{public:int x,y; A(int a,int b):y(b),x(a){}}; A a(1,2); cout<
IN आउटपुट क्या है: class A{public:int x,y; A(int a,int b):y(b),x(a){}}; ए ए(1,2); अदालत
A
12 12
B
21 21
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Members initialized in declaration order (x then y), but initialized to a and b. x=1,y=2. Output: 12.
व्याख्या (हिन्दी) सदस्यों को घोषणा क्रम (x फिर y) में आरंभ किया गया, लेकिन a और b से आरंभ किया गया। x=1,y=2. आउटपुट: 12.
829
EN + हिं
GB What is 'copy-and-swap idiom'?
IN 'कॉपी-एंड-स्वैप मुहावरा' क्या है?
A
Implement assignment via copy ctor and swap for exception safety अपवाद सुरक्षा के लिए कॉपी सीटीआर और स्वैप के माध्यम से असाइनमेंट लागू करें
B
A sorting technique एक छँटाई तकनीक
C
A design pattern एक डिज़ाइन पैटर्न
D
A memory technique एक स्मृति तकनीक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A& operator=(A other){swap(*this,other);return *this;} — strong exception safety guaranteed.
व्याख्या (हिन्दी) A& ऑपरेटर=(एक अन्य){स्वैप(*यह,अन्य);वापसी *यह;} - मजबूत अपवाद सुरक्षा की गारंटी।
830
EN + हिं
GB What is the output: class A{public:int x; A():x(0){cout<<'D';} A(int v):x(v){cout<<'P';} ~A(){cout<<'X';}}; A a; A b(5);
IN आउटपुट क्या है: class A{public:int x; A():x(0){cout
A
DPXX डीपीएक्सएक्स
B
DD डीडी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a: D; b: P. End of scope: ~b(X), ~a(X). Output: DPXX.
व्याख्या (हिन्दी) ए: डी; बी: पी. दायरे का अंत: ~बी(एक्स), ~ए(एक्स)। आउटपुट: DPXX.
831
EN + हिं
GB What is the output: class A{int* p; public: A():p(new int(42)){} ~A(){delete p; cout<<'D';} int get(){return *p;}}; {A a; cout<
IN आउटपुट क्या है: class A{int* p; सार्वजनिक: A():p(new int(42)){} ~A(){delete p; अदालत
A
42D 42डी
B
D42 D42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) get()=42; at scope end: ~A deletes and prints D. Output: 42D.
व्याख्या (हिन्दी) प्राप्त()=42; स्कोप के अंत में: ~ए हटाता है और डी प्रिंट करता है। आउटपुट: 42डी।
832
EN + हिं
GB What is the order of member initialization?
IN सदस्य आरंभीकरण का क्रम क्या है?
A
Declaration order in class, not initializer list order कक्षा में घोषणा क्रम, प्रारंभकर्ता सूची क्रम नहीं
B
Initializer list order आरंभकर्ता सूची क्रम
C
Alphabetical वर्णमाला
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Members initialized in declaration order regardless of the order in the initializer list.
व्याख्या (हिन्दी) आरंभकर्ता सूची में क्रम की परवाह किए बिना सदस्यों ने घोषणा क्रम में आरंभ किया।
833
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
3~ 3~
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints 3; destructor prints ~ at end. Output: 3~.
व्याख्या (हिन्दी) कंस्ट्रक्टर प्रिंट 3; विध्वंसक अंत में ~ प्रिंट करता है। आउटपुट: 3~.
834
EN + हिं
GB What is 'virtual constructor idiom'?
IN 'वर्चुअल कंस्ट्रक्टर मुहावरा' क्या है?
A
Clone pattern: virtual A* clone()=0; returns new derived copy क्लोन पैटर्न: वर्चुअल A* क्लोन()=0; नई व्युत्पन्न प्रतिलिपि लौटाता है
B
Calling virtual in ctor ctor में वर्चुअल कॉलिंग
C
Abstract factory सार कारखाना
D
Same as CRTP सीआरटीपी के समान
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Since constructors can't be virtual, clone() pattern provides polymorphic object creation.
व्याख्या (हिन्दी) चूंकि कंस्ट्रक्टर वर्चुअल नहीं हो सकते, क्लोन() पैटर्न बहुरूपी ऑब्जेक्ट निर्माण प्रदान करता है।
835
EN + हिं
GB What is the output: class A{public:A(){cout<<1;} ~A(){cout<<2;}}; class B:public A{public:B(){cout<<3;} ~B(){cout<<4;}}; B b;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
1342 1342
B
3124 3124
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A() prints 1, B() prints 3, ~B prints 4, ~A prints 2. Output: 1342.
व्याख्या (हिन्दी) A() प्रिंट 1, B() प्रिंट 3, ~B प्रिंट 4, ~A प्रिंट 2. आउटपुट: 1342.
836
EN + हिं
GB What is the output: class A{public:int x=10; A(int v):x(v){} A()=default;}; A a; A b(5); cout<
IN आउटपुट क्या है: class A{public:int x=10; A(int v):x(v){} A()=default;}; ए ए; ए बी(5); अदालत
A
105 105
B
510 510
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a uses =default: x=10 (in-class). b(5): x=5. Output: 105.
व्याख्या (हिन्दी) a =डिफ़ॉल्ट: x=10 (क्लास में) का उपयोग करता है। बी(5): एक्स=5. आउटपुट: 105.
837
EN + हिं
GB What is the output: struct A{int x; ~A(){cout<
IN आउटपुट क्या है: struct A{int x; ~ए(){काउट
A
321 321
B
123 123
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Destructors in reverse order: c,b,a. Prints 3,2,1. Output: 321.
व्याख्या (हिन्दी) उल्टे क्रम में विध्वंसक: सी, बी, ए। 3,2,1 प्रिंट करता है। आउटपुट: 321.
838
EN + हिं
GB What is 'delegating constructor'?
IN 'डेलीगेटिंग कंस्ट्रक्टर' क्या है?
A
Constructor calling another of same class: A():A(0){} कंस्ट्रक्टर उसी क्लास के दूसरे क्लास को कॉल कर रहा है: A():A(0){}
B
Calling base ctor आधार ctor को कॉल कर रहे हैं
C
Calling derived ctor व्युत्पन्न ctor को कॉल करना
D
Copy constructor कंस्ट्रक्टर कॉपी करें
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++11: A():A(0){} delegates to A(int); avoids code duplication.
व्याख्या (हिन्दी) C++11: A():A(0){} A(int); कोड दोहराव से बचाता है।
839
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A():A(99){}}; A a; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A():A(99){}}; ए ए; अदालत
A
99 99
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A() delegates to A(99), x=99. Output: 99.
व्याख्या (हिन्दी) A(), A(99), x=99 को दर्शाता है। आउटपुट: 99.
840
EN + हिं
GB What is the output: class A{public:int x=1,y=2; A(int v):y(v),x(y){}}; A a(5); cout<
IN आउटपुट क्या है: class A{public:int x=1,y=2; A(int v):y(v),x(y){}}; ए ए(5); अदालत
A
25 25
B
15 15
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x initialized first (declaration order): x=y is UB — y not yet initialized. Undefined.
व्याख्या (हिन्दी) x को पहले प्रारंभ किया गया (घोषणा क्रम): x=y यूबी है - y को अभी तक प्रारंभ नहीं किया गया है। अपरिभाषित.
826–840 of 1915