OOP Using C++ — MCQ Practice

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

📚 127 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
127 questions
16
EN + हिं
GB What does 'delete[]' do vs 'delete'?
IN 'डिलीट[]' बनाम 'डिलीट' क्या करता है?
A
delete[] frees array, delete frees single object हटाएँ[] सरणी को मुक्त करता है, हटाएँ एकल वस्तु को मुक्त करता है
B
They are identical वे समान हैं
C
delete[] is for vectors delete[] वैक्टर के लिए है
D
delete[] calls destructor once delete[] डिस्ट्रक्टर को एक बार कॉल करता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete[] calls destructor for each element and frees the array; delete only calls destructor once.
व्याख्या (हिन्दी) हटाएं[] प्रत्येक तत्व के लिए विध्वंसक को कॉल करता है और सरणी को मुक्त करता है; कॉल डिस्ट्रक्टर को केवल एक बार हटाएं।
17
EN + हिं
GB What is the output: int* p=new int(42); cout<<*p; delete p; cout<<*p;
IN आउटपुट क्या है: int* p=new int(42); अदालत
A
42 42 42 42
B
42 0 42 0
C
42 then UB 42 फिर यूबी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Accessing memory after delete is undefined behavior (use-after-free).
व्याख्या (हिन्दी) डिलीट के बाद मेमोरी तक पहुंच अपरिभाषित व्यवहार (उपयोग-बाद-मुक्त) है।
18
EN + हिं
GB What is 'wild pointer'?
IN 'वाइल्ड पॉइंटर' क्या है?
A
Uninitialized pointer अप्रारंभीकृत सूचक
B
Null pointer नल पॉइंटर
C
Pointer past array end सूचक पिछले सरणी अंत
D
Pointer to global वैश्विक की ओर सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A wild pointer is an uninitialized pointer that may point to arbitrary memory location.
व्याख्या (हिन्दी) वाइल्ड पॉइंटर एक अप्रारंभीकृत पॉइंटर है जो मनमाने ढंग से मेमोरी स्थान को इंगित कर सकता है।
19
EN + हिं
GB What is the output: int a=1,b=2; int *p=&a,*q=&b; *p=*q; cout<
IN आउटपुट क्या है: int a=1,b=2; int *p=&a,*q=&b; *पी=*क्यू; अदालत
A
22 22
B
12 12
C
21 21
D
11 11
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) *p=*q copies value of b into a. a becomes 2, b stays 2. Output: 22.
व्याख्या (हिन्दी) *p=*q b के मान को a में कॉपी करता है। ए 2 हो जाता है, बी 2 रहता है। आउटपुट: 22।
20
EN + हिं
GB What is the output: int x=5; int *p=&x; p=nullptr; cout<<(p?*p:0);
IN आउटपुट क्या है: int x=5; int *p=&x; p=nullptr; अदालत
A
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is set to nullptr; (p?*p:0): p is false, returns 0.
व्याख्या (हिन्दी) p को nullptr पर सेट किया गया है; (पी?*पी:0): पी गलत है, 0 लौटाता है।
21
EN + हिं
GB What is std::unique_ptr?
IN std::unique_ptr क्या है?
A
Shared ownership smart pointer साझा स्वामित्व स्मार्ट सूचक
B
Exclusive ownership smart pointer (non-copyable) विशिष्ट स्वामित्व स्मार्ट पॉइंटर (गैर-प्रतिलिपि योग्य)
C
Weak reference smart pointer कमजोर संदर्भ स्मार्ट सूचक
D
Raw pointer wrapper कच्चा सूचक आवरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) unique_ptr has exclusive ownership; it cannot be copied, only moved; deletes object on destruction.
व्याख्या (हिन्दी) अद्वितीय_पीटीआर के पास विशेष स्वामित्व है; इसे कॉपी नहीं किया जा सकता, केवल स्थानांतरित किया जा सकता है; नष्ट होने पर वस्तु को हटा देता है।
22
EN + हिं
GB What is the output: int a[]={10,20,30}; int *p=a; cout<<*(p++);
IN आउटपुट क्या है: int a[]={10,20,30}; int *p=a; अदालत
A
10 10
B
20 20
C
30 30
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p++ returns current p (pointing to a[0]=10), then increments. Dereferences to 10.
व्याख्या (हिन्दी) p++ वर्तमान p लौटाता है (a[0]=10 की ओर इंगित करता है), फिर वृद्धि करता है। 10 से सन्दर्भ.
23
EN + हिं
GB What is 'pointer to function' in C++?
IN C++ में 'पॉइंटर टू फंक्शन' क्या है?
A
A variable storing address of a function किसी फ़ंक्शन का एक वैरिएबल भंडारण पता
B
A function returning pointer एक फ़ंक्शन रिटर्निंग पॉइंटर
C
A member function pointer एक सदस्य फ़ंक्शन सूचक
D
A lambda एक लैम्ब्डा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Function pointers store the address of a function and can be used to call it indirectly.
व्याख्या (हिन्दी) फ़ंक्शन पॉइंटर्स किसी फ़ंक्शन का पता संग्रहीत करते हैं और इसे अप्रत्यक्ष रूप से कॉल करने के लिए उपयोग किया जा सकता है।
24
EN + हिं
GB What is the output: int f(){return 42;} int (*p)()=f; cout<
IN आउटपुट क्या है: int f(){return 42;} int (*p)()=f; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is function pointer to f; p() calls f() which returns 42.
व्याख्या (हिन्दी) p, f का फ़ंक्शन सूचक है; p() f() को कॉल करता है जो 42 लौटाता है।
25
EN + हिं
GB What is the output: int x=10; void *p=&x; cout<<*(int*)p;
IN आउटपुट क्या है: int x=10; शून्य *p=&x; अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) void* p stores address of x; cast to int* and dereference gives 10.
व्याख्या (हिन्दी) void* p, x का पता संग्रहीत करता है; int* पर कास्ट करें और डीरेफ़रेंस 10 देता है।
26
EN + हिं
GB What is the output: int a[]={1,2,3,4,5}; int *p=a+5; cout<<*(p-1);
IN आउटपुट क्या है: int a[]={1,2,3,4,5}; int *p=a+5; अदालत
A
5 5
B
4 4
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p=a+5 (one past end). p-1=&a[4]. *(p-1)=5.
व्याख्या (हिन्दी) p=a+5 (एक पिछला छोर)। पी-1=&ए[4]. *(पी-1)=5.
27
EN + हिं
GB What is shared_ptr reference count?
IN Shared_ptr संदर्भ संख्या क्या है?
A
Number of shared_ptrs owning the object ऑब्जेक्ट के स्वामित्व वाले share_ptrs की संख्या
B
Number of times pointer is used पॉइंटर का उपयोग कितनी बार किया गया है
C
Garbage collection metric कचरा संग्रहण मीट्रिक
D
Memory address स्मृति पता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) shared_ptr maintains a reference count; when it drops to 0, the managed object is deleted.
व्याख्या (हिन्दी) Shared_ptr एक संदर्भ गणना बनाए रखता है; जब यह 0 पर गिरता है, तो प्रबंधित ऑब्जेक्ट हटा दिया जाता है।
28
EN + हिं
GB What is the output: int x=5; auto p=make_unique(x); *p=10; cout<
IN आउटपुट क्या है: int x=5; ऑटो p=make_unique(x); *पी=10; अदालत
A
5 5
B
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) make_unique creates a new int with value x (copy). *p=10 doesn't affect x. Output: 5.
व्याख्या (हिन्दी) make_unique मान x (कॉपी) के साथ एक नया int बनाता है। *p=10 x को प्रभावित नहीं करता. आउटपुट: 5.
29
EN + हिं
GB What is 'aliasing' in the context of pointers?
IN सूचकों के संदर्भ में 'अलियासिंग' क्या है?
A
Two pointers pointing to the same memory एक ही मेमोरी की ओर इशारा करने वाले दो संकेतक
B
A typedef for pointer type सूचक प्रकार के लिए एक टाइपडिफ़
C
Pointer casting सूचक कास्टिंग
D
Reference to pointer सूचक का संदर्भ
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Pointer aliasing occurs when two different pointers point to the same memory location, which can affect optimization.
व्याख्या (हिन्दी) पॉइंटर अलियासिंग तब होता है जब दो अलग-अलग पॉइंटर एक ही मेमोरी लोकेशन की ओर इशारा करते हैं, जो अनुकूलन को प्रभावित कर सकता है।
30
EN + हिं
GB What is the output: int* p=new int[5]{1,2,3,4,5}; cout<
IN आउटपुट क्या है: int* p=new int[5]{1,2,3,4,5}; अदालत
A
5 5
B
4 4
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) new int[5]{1,2,3,4,5} initializes array; p[4]=5.
व्याख्या (हिन्दी) नया int[5]{1,2,3,4,5} सरणी प्रारंभ करता है; पी[4]=5.
16–30 of 127