OOP Using C++ — MCQ Practice

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

📚 187 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
187 questions
1
EN + हिं
GB What is the output of: int main(){int x=10; std::cout<
IN इसका आउटपुट क्या है: int main(){int x=10; std::cout
A
10 12 10 12
B
10 11 10 11
C
11 12 11 12
D
Undefined behavior अपरिभाषित व्यवहार
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Evaluating x++ and ++x in the same expression with no sequence point is undefined behavior in C++.
व्याख्या (हिन्दी) बिना किसी अनुक्रम बिंदु के एक ही अभिव्यक्ति में x++ और ++x का मूल्यांकन करना C++ में अपरिभाषित व्यवहार है।
2
EN + हिं
GB Which of these is NOT a valid C++ translation phase?
IN इनमें से कौन सा वैध C++ अनुवाद चरण नहीं है?
A
Trigraph replacement ट्रिग्राफ प्रतिस्थापन
B
Template instantiation टेम्पलेट इन्स्टेन्शियशन
C
Preprocessing पूर्वप्रसंस्करण
D
Linking लिंक करना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Template instantiation is not a named phase in the 9 translation phases defined by the C++ standard.
व्याख्या (हिन्दी) C++ मानक द्वारा परिभाषित 9 अनुवाद चरणों में टेम्प्लेट इन्स्टेन्शियेशन एक नामित चरण नहीं है।
3
EN + हिं
GB What does the One Definition Rule (ODR) state?
IN वन डेफिनिशन रूल (ओडीआर) क्या बताता है?
A
Every entity must have exactly one definition in the whole program पूरे कार्यक्रम में प्रत्येक इकाई की बिल्कुल एक परिभाषा होनी चाहिए
B
Every function must be defined before use प्रत्येक फ़ंक्शन को उपयोग से पहले परिभाषित किया जाना चाहिए
C
Every class must have a constructor प्रत्येक क्लास में एक कंस्ट्रक्टर होना चाहिए
D
Every variable must be initialized प्रत्येक वेरिएबल को प्रारंभ किया जाना चाहिए
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ODR states each entity (variable, function, class type, etc.) shall be defined no more than once in the entire program, with exceptions for inline and templates.
व्याख्या (हिन्दी) ODR में कहा गया है कि प्रत्येक इकाई (वेरिएबल, फ़ंक्शन, क्लास प्रकार, आदि) को इनलाइन और टेम्प्लेट के अपवादों के साथ, पूरे प्रोग्राम में एक से अधिक बार परिभाषित नहीं किया जाएगा।
4
EN + हिं
GB What is the size of an empty class in C++?
IN C++ में एक खाली कक्षा का आकार क्या है?
A
0 bytes 0 बाइट्स
B
1 byte 1 बाइट
C
4 bytes 4 बाइट्स
D
Implementation defined, but at least 1 कार्यान्वयन परिभाषित, लेकिन कम से कम 1
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) The C++ standard requires a non-zero size for distinct objects; in practice compilers use 1 byte for empty classes.
व्याख्या (हिन्दी) C++ मानक को अलग-अलग वस्तुओं के लिए गैर-शून्य आकार की आवश्यकता होती है; व्यवहार में कंपाइलर खाली कक्षाओं के लिए 1 बाइट का उपयोग करते हैं।
5
EN + हिं
GB Which statement about #include guard vs pragma once is correct?
IN #इनक्लूड गार्ड बनाम प्रैग्मा वन्स के बारे में कौन सा कथन सही है?
A
pragma once is standardized in C++17 Pragma को एक बार C++17 में मानकीकृत किया गया है
B
#include guard is always faster #शामिल गार्ड हमेशा तेज़ होता है
C
pragma once may fail with identical file copies on different paths प्राग्मा एक बार विभिन्न पथों पर समान फ़ाइल प्रतियों के साथ विफल हो सकता है
D
They are identical in behavior वे व्यवहार में एक जैसे हैं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) pragma once is not standardized but widely supported; it can fail when the same file is accessible via multiple symlinks/paths.
व्याख्या (हिन्दी) व्यावहारिकता एक बार मानकीकृत नहीं है लेकिन व्यापक रूप से समर्थित है; यह तब विफल हो सकता है जब एक ही फ़ाइल एकाधिक सिम्लिंक/पथों के माध्यम से पहुंच योग्य हो।
6
EN + हिं
GB What is a 'translation unit' in C++?
IN C++ में 'अनुवाद इकाई' क्या है?
A
A single .cpp file after preprocessing प्रीप्रोसेसिंग के बाद एक एकल .cpp फ़ाइल
B
A compiled .obj file एक संकलित .obj फ़ाइल
C
A single function एक एकल कार्य
D
A single class definition एकल वर्ग परिभाषा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A translation unit is the result of preprocessing a source file — the .cpp file plus all its included headers, with macros expanded.
व्याख्या (हिन्दी) एक अनुवाद इकाई एक स्रोत फ़ाइल को प्रीप्रोसेस करने का परिणाम है - .cpp फ़ाइल और इसके सभी शामिल हेडर, मैक्रोज़ के विस्तार के साथ।
7
EN + हिं
GB What happens when you call a pure virtual function from a constructor?
IN जब आप किसी कंस्ट्रक्टर से शुद्ध वर्चुअल फ़ंक्शन को कॉल करते हैं तो क्या होता है?
A
Calls the derived class override व्युत्पन्न वर्ग को ओवरराइड कहता है
B
Undefined behavior अपरिभाषित व्यवहार
C
Compile error संकलन त्रुटि
D
Calls the pure virtual, which crashes शुद्ध वर्चुअल को कॉल करता है, जो क्रैश हो जाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Calling a pure virtual function (directly or indirectly) from a constructor or destructor is undefined behavior.
व्याख्या (हिन्दी) किसी कंस्ट्रक्टर या डिस्ट्रक्टर से शुद्ध वर्चुअल फ़ंक्शन (प्रत्यक्ष या अप्रत्यक्ष रूप से) को कॉल करना अपरिभाषित व्यवहार है।
8
EN + हिं
GB What is the difference between 'struct' and 'class' in C++?
IN C++ में 'स्ट्रक्चर' और 'क्लास' के बीच क्या अंतर है?
A
struct cannot have member functions संरचना में सदस्य कार्य नहीं हो सकते
B
Default access is public in struct, private in class डिफ़ॉल्ट पहुंच संरचना में सार्वजनिक है, कक्षा में निजी है
C
struct cannot have inheritance संरचना में विरासत नहीं हो सकती
D
struct is a C feature, class is C++ only struct एक C फीचर है, क्लास केवल C++ है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) The only differences are default access specifier (public for struct, private for class) and default inheritance (public for struct, private for class).
व्याख्या (हिन्दी) एकमात्र अंतर डिफ़ॉल्ट एक्सेस विनिर्देशक (संरचना के लिए सार्वजनिक, वर्ग के लिए निजी) और डिफ़ॉल्ट विरासत (संरचना के लिए सार्वजनिक, वर्ग के लिए निजी) हैं।
9
EN + हिं
GB What does 'extern C' do in C++?
IN C++ में 'एक्सटर्न C' क्या करता है?
A
Imports C standard library सी मानक पुस्तकालय आयात करता है
B
Disables name mangling for the declared function घोषित फ़ंक्शन के लिए नाम प्रबंधन अक्षम करता है
C
Makes function visible only in current file फ़ंक्शन को केवल वर्तमान फ़ाइल में दृश्यमान बनाता है
D
Enables C linkage for all subsequent code बाद के सभी कोड के लिए C लिंकेज सक्षम करता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) extern "C" tells the compiler to use C linkage (no name mangling) so C++ code can link with C compiled code.
व्याख्या (हिन्दी) बाहरी "सी" कंपाइलर को सी लिंकेज (कोई नाम मैंगलिंग नहीं) का उपयोग करने के लिए कहता है ताकि सी++ कोड सी संकलित कोड के साथ लिंक हो सके।
10
EN + हिं
GB In C++, what is the result of sizeof('A')?
IN C++ में, sizeof('A') का परिणाम क्या है?
A
1 (always) 1 (हमेशा)
B
sizeof(int) आकार(पूर्णांक)
C
4 on most platforms अधिकांश प्लेटफार्मों पर 4
D
sizeof(char) आकार(चार)
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) In C++, character literals have type char, so sizeof('A') == sizeof(char) == 1. (Unlike C where 'A' has type int.)
व्याख्या (हिन्दी) C++ में, वर्ण शाब्दिक का प्रकार char है, इसलिए sizeof('A') == sizeof(char) == 1. (C के विपरीत जहां 'A' का प्रकार int है।)
11
EN + हिं
GB What is the output of: cout << (true + true + true);
IN इसका आउटपुट क्या है: कॉउट
A
true सत्य
B
1 1
C
3 3
D
Compiler error संकलक त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) bool values are promoted to int in arithmetic: true=1, so 1+1+1=3.
व्याख्या (हिन्दी) अंकगणित में बूल मानों को int में पदोन्नत किया जाता है: true=1, इसलिए 1+1+1=3।
12
EN + हिं
GB Which C++ feature allows a function to have multiple definitions with different parameter types?
IN कौन सी C++ सुविधा किसी फ़ंक्शन को विभिन्न पैरामीटर प्रकारों के साथ एकाधिक परिभाषाएँ देने की अनुमति देती है?
A
Overriding अधिभावी
B
Overloading अधिक भार
C
Templates टेम्पलेट्स
D
Polymorphism बहुरूपता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Function overloading allows multiple functions with the same name but different parameter lists in the same scope.
व्याख्या (हिन्दी) फ़ंक्शन ओवरलोडिंग एक ही नाम के साथ कई फ़ंक्शन की अनुमति देता है लेकिन एक ही दायरे में विभिन्न पैरामीटर सूचियों की अनुमति देता है।
13
EN + हिं
GB What is the output: int x=5; cout << x<<2;
IN आउटपुट क्या है: int x=5; अदालत
A
20 20
B
7 7
C
52 52
D
Compiler error संकलक त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) cout << x<<2 is parsed as (cout << x) << 2; which shifts x left by 2 bits: 5 << 2 = 20. Wait — actually cout<
व्याख्या (हिन्दी) अदालत
14
EN + हिं
GB Which of the following correctly declares a reference to a pointer to const int?
IN निम्नलिखित में से कौन सही ढंग से const int के लिए एक सूचक के संदर्भ की घोषणा करता है?
A
int const *&rp इंट कॉन्स्ट *&आरपी
B
const int* &rp स्थिरांक int* &rp
C
int *const &rp int * स्थिरांक और आरपी
D
Both A and B ए और बी दोनों
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both 'int const *&rp' and 'const int* &rp' declare a reference to a pointer to const int; they are identical.
व्याख्या (हिन्दी) 'int const *&rp' और 'const int* &rp' दोनों const int के लिए एक सूचक का संदर्भ घोषित करते हैं; वे समान हैं.
15
EN + हिं
GB What is 'name mangling' in C++?
IN C++ में 'नेम मैंगलिंग' क्या है?
A
Renaming variables for security सुरक्षा के लिए वेरिएबल का नाम बदलना
B
Encoding function names with type info for linking लिंक करने के लिए प्रकार की जानकारी के साथ फ़ंक्शन नामों को एन्कोड करना
C
Obfuscating source code अस्पष्ट स्रोत कोड
D
Compressing symbol table संपीड़न प्रतीक तालिका
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Name mangling encodes the function's name, parameter types, and namespace into a unique symbol name, enabling function overloading in object files.
व्याख्या (हिन्दी) नेम मैंगलिंग फ़ंक्शन के नाम, पैरामीटर प्रकार और नेमस्पेस को एक अद्वितीय प्रतीक नाम में एन्कोड करता है, जिससे ऑब्जेक्ट फ़ाइलों में फ़ंक्शन ओवरलोडिंग सक्षम हो जाती है।
1–15 of 187