OOP Using C++ — MCQ Practice

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

📚 132 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
132 questions
16
EN + हिं
GB What is the output: int f(int& a, int b){ a=10; return a+b; } int x=5; cout<
IN आउटपुट क्या है: int f(int& a, int b){ a=10; वापसी a+b; } int x=5; अदालत
A
10 10
B
15 15
C
20 20
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b is passed by value (=5 at call time). Inside f: a=10, return 10+5=15.
व्याख्या (हिन्दी) b को मान (=कॉल समय पर 5) से पारित किया जाता है। f के अंदर: a=10, वापसी 10+5=15।
17
EN + हिं
GB What is the output: auto f=[](auto x){ return x*2; }; cout<
IN आउटपुट क्या है: auto f=[](auto x){ return x*2; }; अदालत
A
105 105
B
Compile error संकलन त्रुटि
C
105.0 105.0
D
Generic lambda requires C++20 जेनेरिक लैम्ब्डा को C++20 की आवश्यकता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Generic lambda (C++14+): f(5)=10, f(2.5)=5.0. cout<<10<<5 outputs '105'.
व्याख्या (हिन्दी) जेनेरिक लैम्ब्डा (C++14+): f(5)=10, f(2.5)=5.0। अदालत
18
EN + हिं
GB What happens when a function returns a reference to a local variable?
IN क्या होता है जब कोई फ़ंक्शन किसी स्थानीय चर का संदर्भ लौटाता है?
A
Compile error always हमेशा त्रुटि संकलित करें
B
Undefined behavior (dangling reference) अपरिभाषित व्यवहार (लटकता संदर्भ)
C
Reference extends variable lifetime संदर्भ परिवर्तनीय जीवनकाल का विस्तार करता है
D
Safe if variable is static यदि परिवर्तनशील स्थिर है तो सुरक्षित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Returning a reference to a local variable creates a dangling reference (undefined behavior) because the local is destroyed on return.
व्याख्या (हिन्दी) स्थानीय चर के संदर्भ को वापस करने से एक लटकता हुआ संदर्भ (अपरिभाषित व्यवहार) बनता है क्योंकि वापसी पर स्थानीय नष्ट हो जाता है।
19
EN + हिं
GB What is the output: int f(){ return 1; } int g(){ return 2; } cout<
IN आउटपुट क्या है: int f(){ return 1; } int g(){वापसी 2; } कोउट
A
3 3
B
12 12
C
Unspecified order अनिर्दिष्ट आदेश
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f()+g() = 1+2 = 3. The order of evaluation of f() and g() is unspecified but result is deterministic.
व्याख्या (हिन्दी) f()+g() = 1+2 = 3. f() और g() के मूल्यांकन का क्रम अनिर्दिष्ट है लेकिन परिणाम नियतात्मक है।
20
EN + हिं
GB What is 'perfect forwarding' in C++?
IN C++ में 'परफेक्ट फ़ॉरवर्डिंग' क्या है?
A
Passing arguments preserving their value category (lvalue/rvalue) उनकी मूल्य श्रेणी (lvalue/rvalue) को संरक्षित करते हुए तर्क पारित करना
B
Inlining function calls इनलाइनिंग फ़ंक्शन कॉल
C
Forwarding return values वापसी मान अग्रेषित करना
D
Template specialization forwarding टेम्पलेट विशेषज्ञता अग्रेषण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) std::forward(arg) preserves the lvalue/rvalue nature of the argument for perfect forwarding in template functions.
व्याख्या (हिन्दी) std::forward(arg) टेम्प्लेट फ़ंक्शंस में सही अग्रेषण के लिए तर्क की lvalue/rvalue प्रकृति को संरक्षित करता है।
21
EN + हिं
GB What is the output: void f(int x){ x=100; } int a=5; f(a); cout<
IN आउटपुट क्या है: void f(int x){ x=100; } int a=5; एफ(ए); अदालत
A
100 100
B
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x is passed by value; modifying x inside f doesn't affect a. Output: 5.
व्याख्या (हिन्दी) x मान द्वारा पारित किया गया है; x को f के अंदर संशोधित करने से a प्रभावित नहीं होता है। आउटपुट: 5.
22
EN + हिं
GB What is the output: int f(int n){ return n?n+f(n-1):0; } cout<
IN आउटपुट क्या है: int f(int n){ return n?n+f(n-1):0; } कोउट
A
10 10
B
4 4
C
24 24
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f(4)=4+f(3)=4+3+f(2)=4+3+2+f(1)=4+3+2+1+f(0)=4+3+2+1+0=10.
व्याख्या (हिन्दी) f(4)=4+f(3)=4+3+f(2)=4+3+2+f(1)=4+3+2+1+f(0)=4+3+2+1+0=10.
23
EN + हिं
GB What is 'memoization' in the context of recursive functions?
IN पुनरावर्ती कार्यों के संदर्भ में 'संस्मरण' क्या है?
A
Caching results of function calls फ़ंक्शन कॉल के कैशिंग परिणाम
B
Memory optimization technique मेमोरी अनुकूलन तकनीक
C
Using static variables स्थैतिक चर का उपयोग करना
D
Tail call optimization टेल कॉल अनुकूलन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Memoization stores the results of expensive function calls and returns cached results when the same inputs occur again.
व्याख्या (हिन्दी) मेमोइज़ेशन महंगे फ़ंक्शन कॉल के परिणामों को संग्रहीत करता है और समान इनपुट दोबारा होने पर कैश्ड परिणाम लौटाता है।
24
EN + हिं
GB What is the output: int x=10; auto f=[&](){ return ++x; }; cout<
IN आउटपुट क्या है: int x=10; ऑटो f=[&](){वापसी++x; }; अदालत
A
1112 1112
B
Unspecified अनिर्दिष्ट
C
1112 1112
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Order of evaluation of arguments to << is unspecified before C++17; both calls modify x but print order is unspecified.
व्याख्या (हिन्दी) तर्कों के मूल्यांकन का क्रम
25
EN + हिं
GB What is 'noexcept' specifier in C++?
IN C++ में 'noexcept' विनिर्देशक क्या है?
A
Guarantees function throws no exceptions गारंटी फ़ंक्शन कोई अपवाद नहीं देता है
B
Prevents exception handling अपवाद प्रबंधन को रोकता है
C
Makes function constexpr फ़ंक्शन कॉन्स्टेक्सपीआर बनाता है
D
Catches all exceptions सभी अपवादों को पकड़ता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) noexcept declares that a function will not throw exceptions; if it does, std::terminate is called.
व्याख्या (हिन्दी) noexcept घोषित करता है कि कोई फ़ंक्शन अपवाद नहीं फेंकेगा; यदि ऐसा होता है, तो std::terminet को कॉल किया जाता है।
26
EN + हिं
GB What is the output: int f(int x, int y=x){ return x+y; }
IN आउटपुट क्या है: int f(int x, int y=x){ return x+y; }
A
Works in C++17 C++17 में काम करता है
B
Compile error संकलन त्रुटि
C
Undefined behavior अपरिभाषित व्यवहार
D
Works if x is const यदि x स्थिरांक है तो काम करता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default argument cannot refer to another parameter; this is a compile error.
व्याख्या (हिन्दी) डिफ़ॉल्ट तर्क किसी अन्य पैरामीटर को संदर्भित नहीं कर सकता; यह एक संकलन त्रुटि है.
27
EN + हिं
GB What is the output: void f(int* p){ *p=20; } int a=10; f(&a); cout<
IN आउटपुट क्या है: void f(int* p){ *p=20; } int a=10; एफ(&ए); अदालत
A
10 10
B
20 20
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f takes pointer to int, dereferences and sets to 20, modifying a. Output: 20.
व्याख्या (हिन्दी) f पॉइंटर को int, dereferences पर ले जाता है और a को संशोधित करते हुए 20 पर सेट करता है। आउटपुट: 20.
28
EN + हिं
GB What is the output: int f(int n){ return n>0?f(n/2)+1:0; } cout<
IN आउटपुट क्या है: int f(int n){ return n>0?f(n/2)+1:0; } कोउट
A
3 3
B
4 4
C
8 8
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f(8)=f(4)+1=f(2)+2=f(1)+3=f(0)+4=0+4=4. Wait: f(8)=f(4)+1; f(4)=f(2)+1; f(2)=f(1)+1; f(1)=f(0)+1=1; f(2)=2; f(4)=3; f(8)=4. Answer: 4.
व्याख्या (हिन्दी) f(8)=f(4)+1=f(2)+2=f(1)+3=f(0)+4=0+4=4. रुको: f(8)=f(4)+1; f(4)=f(2)+1; f(2)=f(1)+1; f(1)=f(0)+1=1; एफ(2)=2; एफ(4)=3; एफ(8)=4. उत्तर: 4.
29
EN + हिं
GB What is 'function template argument deduction'?
IN 'फ़ंक्शन टेम्प्लेट तर्क कटौती' क्या है?
A
Compiler deducing template args from function arguments कंपाइलर फ़ंक्शन तर्कों से टेम्प्लेट तर्क निकालता है
B
Manually specifying template arguments टेम्पलेट तर्कों को मैन्युअल रूप से निर्दिष्ट करना
C
Runtime type deduction रनटाइम प्रकार की कटौती
D
Only works with auto केवल ऑटो के साथ काम करता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) When calling a function template, the compiler deduces template type parameters from the types of the provided arguments.
व्याख्या (हिन्दी) फ़ंक्शन टेम्प्लेट को कॉल करते समय, कंपाइलर प्रदान किए गए तर्कों के प्रकारों से टेम्प्लेट प्रकार के पैरामीटर निकालता है।
30
EN + हिं
GB What is the output: int f(int x){ return x; } double f(double x){ return x; } cout<
IN आउटपुट क्या है: int f(int x){ return x; } डबल एफ (डबल एक्स) { रिटर्न एक्स; } कोउट
A
1 1
B
1.0 1.0
C
Ambiguous अस्पष्ट
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1 is int literal; exact match to f(int). Output: 1.
व्याख्या (हिन्दी) 1 पूर्णांक शाब्दिक है; f(int) से सटीक मिलान। आउटपुट: 1.
16–30 of 132