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
31
EN + हिं
GB What is the output: class A{public:int x=0; void f(){x++;}}; A a1,a2; a1.f();a1.f(); a2.f(); cout<
IN आउटपुट क्या है: class A{public:int x=0; शून्य f(){x++;}}; ए ए1,ए2; a1.f();a1.f(); a2.f(); अदालत
A
21 21
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a1.x=2, a2.x=1. Output: 21.
व्याख्या (हिन्दी) a1.x=2, a2.x=1. आउटपुट: 21.
32
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} int get()const{return x;} void set(int v){x=v;}}; A a(5); a.set(10); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} int get()const{return x;} void set(int v){x=v;}}; ए ए(5); ए.सेट(10); अदालत
A
10 10
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) set(10) changes x=10. get()=10. Output: 10.
व्याख्या (हिन्दी) सेट(10) x=10 बदलता है। प्राप्त करें()=10. आउटपुट: 10.
33
EN + हिं
GB What is 'rule of zero'?
IN 'शून्य का नियम' क्या है?
A
Don't define any special members; use smart pointers/containers किसी विशेष सदस्य को परिभाषित न करें; स्मार्ट पॉइंटर्स/कंटेनर्स का उपयोग करें
B
No constructors at all बिल्कुल कोई कंस्ट्रक्टर नहीं
C
Zero members class शून्य सदस्य वर्ग
D
Empty class खाली कक्षा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If a class uses smart pointers and standard containers, compiler-generated specials work correctly; define none.
व्याख्या (हिन्दी) यदि कोई क्लास स्मार्ट पॉइंटर्स और मानक कंटेनरों का उपयोग करता है, तो कंपाइलर-जनरेटेड स्पेशल सही ढंग से काम करते हैं; किसी को परिभाषित न करें.
34
EN + हिं
GB What is the output: class A{public:static int n; A(){n++;} ~A(){n (1, 6, 78, 8, 4, 'What is the output: class A{int x=5; public: int f()const{return x;} void g(){x=10;}}; A a; cout<
IN आउटपुट क्या है: class A{public:static int n; A(){n++;} ~A(){n (1, 6, 78, 8, 4, 'आउटपुट क्या है: क्लास ए{int x=5; सार्वजनिक: int f()const{return x;} void g(){x=10;}}; A a; cout
A
Conv op: class->other type; constructor: other type->class रूपांतरण ऑप: वर्ग->अन्य प्रकार; कंस्ट्रक्टर: अन्य प्रकार->वर्ग
B
Same thing एक ही बात
C
Both are implicit दोनों अन्तर्निहित हैं
D
Neither is explicit कोई भी स्पष्ट नहीं है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator int() converts class to int; A(int) converts int to class.
व्याख्या (हिन्दी) ऑपरेटर int() क्लास को int में परिवर्तित करता है; A(int) int को क्लास में परिवर्तित करता है।
35
EN + हिं
GB What is the output: class A{int x=5; public: int f()const{return x;} void g(){x=10;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: int f()const{return x;} void g(){x=10;}}; ए ए; अदालत
A
510 510
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Initial f()=5; g() sets x=10; f()=10. Output: 510.
व्याख्या (हिन्दी) आरंभिक f()=5; g() x=10 सेट करता है; एफ()=10. आउटपुट: 510.
36
EN + हिं
GB What is 'conversion operator' vs constructor conversion?
IN 'रूपांतरण ऑपरेटर' बनाम कंस्ट्रक्टर रूपांतरण क्या है?
A
Conv op: class->other type; constructor: other type->class रूपांतरण ऑप: वर्ग->अन्य प्रकार; कंस्ट्रक्टर: अन्य प्रकार->वर्ग
B
Same thing एक ही बात
C
Both are implicit दोनों अन्तर्निहित हैं
D
Neither is explicit कोई भी स्पष्ट नहीं है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator int() converts class to int; A(int) converts int to class.
व्याख्या (हिन्दी) ऑपरेटर int() क्लास को int में परिवर्तित करता है; A(int) int को क्लास में परिवर्तित करता है।
37
EN + हिं
GB What is the output: class A{public:int x; A(int v=0):x(v){}}; A a[3]; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v=0):x(v){}}; ए ए[3]; अदालत
A
000 000
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
123 123
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default ctor A() sets x=0. All elements x=0. Output: 000.
व्याख्या (हिन्दी) डिफ़ॉल्ट ctor A() x=0 सेट करता है। सभी तत्व x=0. आउटपुट: 000.
38
EN + हिं
GB What is the output: class A{public:int x; A():x(0){} A(const A& o):x(o.x+1){}}; A a; A b=a; A c=b; cout<
IN आउटपुट क्या है: class A{public:int x; A():x(0){} A(const A& o):x(o.x+1){}}; ए ए; ए बी=ए; ए सी=बी; अदालत
A
012 012
B
000 000
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=0; b.x=a.x+1=1; c.x=b.x+1=2. Output: 012.
व्याख्या (हिन्दी) a.x=0; b.x=a.x+1=1; c.x=b.x+1=2. आउटपुट: 012.
39
EN + हिं
GB What is the output: class A{public:int x=0; A& inc(){x++;return *this;}}; A a; cout<
IN आउटपुट क्या है: class A{public:int x=0; A& inc(){x++;रिटर्न *यह;}}; ए ए; अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each inc() increments x; chained. x=3. Output: 3.
व्याख्या (हिन्दी) प्रत्येक inc() वेतन वृद्धि x; जंजीर. एक्स=3. आउटपुट: 3.
40
EN + हिं
GB What is 'aggregate initialization' for class?
IN कक्षा के लिए 'समग्र आरंभीकरण' क्या है?
A
Class with no user-defined ctor, no private data: A a{1,2}; बिना उपयोगकर्ता-परिभाषित ctor वाला वर्ग, कोई निजी डेटा नहीं: A a{1,2};
B
Any class कोई भी वर्ग
C
POD only केवल पीओडी
D
Struct only केवल संरचना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++20 relaxed: no user-provided ctor, no private non-static members, no virtual functions.
व्याख्या (हिन्दी) C++20 में छूट: कोई उपयोगकर्ता द्वारा प्रदत्त ctor नहीं, कोई निजी गैर-स्थैतिक सदस्य नहीं, कोई वर्चुअल फ़ंक्शन नहीं।
41
EN + हिं
GB What is the output: class A{public:int x,y; A(int a,int b):x(a),y(b){} int sum()const{return x+y;}}; A a(3,4); cout<
IN आउटपुट क्या है: class A{public:int x,y; A(int a,int b):x(a),y(b){} int sum()const{return x+y;}}; ए ए(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.
42
EN + हिं
GB What is the output: class A{public:int x=10; int f(int y){return x+y;}}; A a; cout<
IN आउटपुट क्या है: class A{public:int x=10; int f(int y){रिटर्न x+y;}}; ए ए; अदालत
A
15 15
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 10+5=15. Output: 15.
व्याख्या (हिन्दी) 10+5=15. आउटपुट: 15.
43
EN + हिं
GB What is 'friend function' accessing private?
IN प्राइवेट एक्सेसिंग 'फ्रेंड फंक्शन' क्या है?
A
Declared inside class; can access private members कक्षा के अंदर घोषित; निजी सदस्यों तक पहुंच सकते हैं
B
Must be member सदस्य होना चाहिए
C
Cannot access protected सुरक्षित तक पहुंच नहीं हो सकती
D
C++17 only केवल सी++17
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) friend void f(A&); inside class grants f access to A's private/protected members.
व्याख्या (हिन्दी) मित्र शून्य f(A&); अंदर की कक्षा ए के निजी/संरक्षित सदस्यों तक पहुंच प्रदान करती है।
44
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} friend int get(A a){return a.x;}}; A a(42); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} मित्र int get(A a){return a.x;}}; ए ए(42); अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) get() is friend; accesses a.x=42. Output: 42.
व्याख्या (हिन्दी) get() मित्र है; a.x=42 तक पहुँचता है। आउटपुट: 42.
45
EN + हिं
GB What is the output: class A{public: A(){} A(A&&)=delete;}; A f(){return A();} A a=f();
IN आउटपुट क्या है: वर्ग A{सार्वजनिक: A(){} A(A&&)=delete;}; A f(){वापसी A();} A a=f();
A
Compile error संकलन त्रुटि
B
OK (compiles) ठीक है (संकलन)
C
Undefined अपरिभाषित
D
No output उत्पादन नही
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++17 mandatory copy elision: return A() doesn't invoke any constructor; compiles even with deleted move. Output: OK (compiles, no output).
व्याख्या (हिन्दी) C++17 अनिवार्य प्रतिलिपि elision: रिटर्न A() किसी भी कंस्ट्रक्टर को आमंत्रित नहीं करता है; हटाई गई चाल के साथ भी संकलित करता है। आउटपुट: ठीक है (संकलन, कोई आउटपुट नहीं)।
31–45 of 106