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
901
EN + हिं
GB What is 'virtual function table pointer (vptr)'?
IN 'वर्चुअल फंक्शन टेबल पॉइंटर (वीपीटीआर)' क्या है?
A
Pointer in each polymorphic object to its class vtable प्रत्येक बहुरूपी वस्तु में उसके वर्ग vtable के लिए सूचक
B
A static variable एक स्थिर चर
C
A function pointer array एक फ़ंक्शन सूचक सरणी
D
A compiler macro एक कंपाइलर मैक्रो
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) vptr is automatically added by compiler; points to vtable with function pointers for virtual functions.
व्याख्या (हिन्दी) वीपीटीआर स्वचालित रूप से कंपाइलर द्वारा जोड़ा जाता है; वर्चुअल फ़ंक्शंस के लिए फ़ंक्शन पॉइंटर्स के साथ vtable को इंगित करता है।
902
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;} void g(){A::f(); f();}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
22 22
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f()=1; f()=B::f()=2. Output: 12.
व्याख्या (हिन्दी) ए::एफ()=1; एफ()=बी::एफ()=2. आउटपुट: 12.
903
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';}}; class B:public A{}; class C:public B{public:void f()override{cout<<'C';}}; A*p=new C; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
C सी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::f() overrides A::f(). Output: C.
व्याख्या (हिन्दी) C::f() A::f() को ओवरराइड करता है। आउटपुट: सी.
904
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void g(){cout<<'G';}}; class B:public A{public:void f()override{cout<<'B';} using A::g;}; A*p=new B; p->f(); p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BG बीजी
B
BA बी ० ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f()=B::f()=B; p->g()=A::g()=G. Output: BG.
व्याख्या (हिन्दी) p->f()=B::f()=B; p->g()=A::g()=G. आउटपुट: बीजी.
905
EN + हिं
GB What is the output: class A{public:virtual int f(){return 0;}}; class B:public A{int x; public:B(int v):x(v){} int f()override{return x;}}; A*p=new B(99); cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 0;}}; कक्षा बी:सार्वजनिक ए{int x; सार्वजनिक:बी(int v):x(v){} int f()ओवरराइड{रिटर्न x;}}; ए*पी=नया बी(99); अदालत
A
99 99
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=x=99. Output: 99.
व्याख्या (हिन्दी) बी::f()=x=99. आउटपुट: 99.
906
EN + हिं
GB What is 'dynamic_cast to void*'?
IN 'डायनामिक_कास्ट टू वॉयड*' ​​क्या है?
A
Returns pointer to most-derived object सर्वाधिक-व्युत्पन्न ऑब्जेक्ट पर पॉइंटर लौटाता है
B
Returns null शून्य लौटाता है
C
Same as static_cast स्टेटिक_कास्ट के समान
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) dynamic_cast(ptr) returns pointer to the complete most-derived object.
व्याख्या (हिन्दी) डायनामिक_कास्ट(पीटीआर) संपूर्ण सर्वाधिक-व्युत्पन्न ऑब्जेक्ट पर पॉइंटर लौटाता है।
907
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f(){cout<<'B';}}; A*arr[2]={new B,new B}; for(auto p:arr) p->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
BB बी बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
AA
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both B::f(). Output: BB.
व्याख्या (हिन्दी) दोनों B::f(). आउटपुट: बीबी.
908
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; void call(A a){a.f();} B b; call(b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) call takes A by value — slices b. a.f()=A::f()=1. Output: 1.
व्याख्या (हिन्दी) कॉल ए को मान के आधार पर लेती है - स्लाइस बी। a.f()=A::f()=1. आउटपुट: 1.
909
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::f();}}; A*p=new B; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BA बी ० ए
B
AB अब
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=B, then A::f()=A. Output: BA.
व्याख्या (हिन्दी) बी::एफ()=बी, फिर ए::एफ()=ए। आउटपुट: बी.ए.
910
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} virtual int get(){return x;}}; class B:public A{int y; public: B(int a,int b):A(a),y(b){} int get()override{return A::get()+y;}}; A*p=new B(3,4); cout<get();
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} वर्चुअल int get(){return x;}}; कक्षा बी:सार्वजनिक ए{इंट वाई; सार्वजनिक: B(int a,int b):A(a),y(b){} int get()override{return A::get()+y;}}; ए*पी=नया बी(3,4); अदालत
A
7 7
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
911
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual void g(){f();}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी शून्य g(){f();}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
A
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls virtual f(): B::f()=B. Output: B.
व्याख्या (हिन्दी) g() वर्चुअल f() को कॉल करता है: B::f()=B। आउटपुट: बी.
912
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} }; class B:public A{}; class C:public A{}; B b; C c; A*arr[]={&b,&c}; for(auto p:arr) p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
AA
B
BC ईसा पूर्व
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both inherit A::f(). Output: AA.
व्याख्या (हिन्दी) दोनों को A::f() विरासत में मिला है। आउटपुट: एए.
913
EN + हिं
GB What is 'virtual dispatch performance cost'?
IN 'वर्चुअल डिस्पैच प्रदर्शन लागत' क्या है?
A
Indirect call via vptr; possible cache miss; cannot inline वीपीटीआर के माध्यम से अप्रत्यक्ष कॉल; संभावित कैश मिस; इनलाइन नहीं कर सकते
B
No overhead कोई उपरिव्यय नहीं
C
Same as direct call सीधी कॉल के समान
D
Compile-time resolution संकलन-समय संकल्प
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual calls require pointer dereference + table lookup; prevent inlining; may cause branch misprediction.
व्याख्या (हिन्दी) वर्चुअल कॉल के लिए पॉइंटर डीरेफ़रेंस + टेबल लुकअप की आवश्यकता होती है; इनलाइनिंग को रोकें; शाखा का गलत पूर्वानुमान हो सकता है.
914
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; A a; B b; A*p=&a; p->f(); p=&b; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): A::f()=1; p=&b; p->f(): B::f()=2. Output: 12.
व्याख्या (हिन्दी) p->f(): A::f()=1; पी=&बी; p->f(): B::f()=2. आउटपुट: 12.
915
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} void g(){cout<<'G'; f();}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
GB जीबी
B
GA गा
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() prints G then calls virtual f(): B::f()=B. Output: GB.
व्याख्या (हिन्दी) g() G को प्रिंट करता है फिर वर्चुअल f() को कॉल करता है: B::f()=B। आउटपुट: जीबी.
901–915 of 1915