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
196
EN + हिं
GB What is the output: int a[]={1,2,3,4,5}; int *p=a+2; cout<
IN आउटपुट क्या है: int a[]={1,2,3,4,5}; int *p=a+2; अदालत
A
234 234
B
345 345
C
123 123
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p=a+2=&a[2]. p[-1]=a[1]=2, p[0]=a[2]=3, p[1]=a[3]=4. Output: 234.
व्याख्या (हिन्दी) पी=ए+2=&ए[2]. पी[-1]=ए[1]=2, पी[0]=ए[2]=3, पी[1]=ए[3]=4। आउटपुट: 234.
197
EN + हिं
GB What is the output: void* p=(void*)42; cout<<(int)(size_t)p;
IN आउटपुट क्या है: void* p=(void*)42; अदालत
A
42 42
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Casting integer to void* and back is implementation-defined; on most platforms returns 42.
व्याख्या (हिन्दी) पूर्णांक को void* और वापस कास्ट करना कार्यान्वयन-परिभाषित है; अधिकांश प्लेटफ़ॉर्म पर 42 रिटर्न मिलता है।
198
EN + हिं
GB What is a 'smart pointer' in C++?
IN C++ में 'स्मार्ट पॉइंटर' क्या है?
A
A pointer with automatic memory management स्वचालित मेमोरी प्रबंधन वाला एक सूचक
B
A pointer to a class किसी वर्ग के लिए सूचक
C
A faster raw pointer एक तेज़ कच्चा सूचक
D
A compile-time pointer एक संकलन-समय सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Smart pointers (unique_ptr, shared_ptr, weak_ptr) manage heap memory automatically through RAII.
व्याख्या (हिन्दी) स्मार्ट पॉइंटर्स (यूनिक_पीटीआर, शेयर्ड_पीटीआर, वीक_पीटीआर) आरएआईआई के माध्यम से हीप मेमोरी को स्वचालित रूप से प्रबंधित करते हैं।
199
EN + हिं
GB What is the output: int x=10; const int *p=&x; *p=20; cout<
IN आउटपुट क्या है: int x=10; स्थिरांक int *p=&x; *पी=20; अदालत
A
10 10
B
20 20
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is pointer to const int; *p=20 tries to modify through const pointer: compile error.
व्याख्या (हिन्दी) p const int का सूचक है; *p=20 कॉन्स्ट पॉइंटर के माध्यम से संशोधित करने का प्रयास करता है: संकलन त्रुटि।
200
EN + हिं
GB What is the output: int x=5,y=10; int *p=&x; swap(p,&y); cout<
IN आउटपुट क्या है: int x=5,y=10; int *p=&x; स्वैप (पी,&वाई); अदालत
A
Undefined अपरिभाषित
B
5 10 5 10
C
Compile error संकलन त्रुटि
D
10 5 10 5
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) swap(p, &y) — p is int*, &y is int*. Types match; swaps p to point to y. x and y values unchanged. Actually this is swapping the pointer, not the values. So x=5,y=10 unchanged. Wait, std::swap on pointers swaps what they point to — no, it swaps the pointers themselves. cout<
व्याख्या (हिन्दी) स्वैप(p, &y) - p int* है, &y int* है। प्रकार मेल खाते हैं; Y को इंगित करने के लिए p को स्वैप करता है। x और y मान अपरिवर्तित हैं। दरअसल यह पॉइंटर की अदला-बदली है, मूल्यों की नहीं। तो x=5,y=10 अपरिवर्तित। रुको, पॉइंटर्स पर std::swap वे जो इंगित करते हैं उसे स्वैप करता है - नहीं, यह पॉइंटर्स को स्वयं स्वैप करता है। अदालत
201
EN + हिं
GB What is 'double pointer' in C++?
IN C++ में 'डबल पॉइंटर' क्या है?
A
Pointer to a pointer सूचक को सूचक
B
Pointer to double type डबल टाइप करने के लिए सूचक
C
Two pointers दो सूचक
D
64-bit pointer 64-बिट सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A double pointer (int**) stores the address of another pointer.
व्याख्या (हिन्दी) एक डबल पॉइंटर (int**) दूसरे पॉइंटर का पता संग्रहीत करता है।
202
EN + हिं
GB What is the output: int arr[]={1,2,3}; int *p=arr; cout<
IN आउटपुट क्या है: int arr[]={1,2,3}; int *p=arr; अदालत
A
Address 2 पता 2
B
1 2 1 2
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p++ and *p in same cout without sequencing (pre-C++17) is unspecified/undefined behavior.
व्याख्या (हिन्दी) p++ और *p अनुक्रमण के बिना एक ही कॉउट में (पूर्व-C++17) अनिर्दिष्ट/अपरिभाषित व्यवहार है।
203
EN + हिं
GB What is the output: int x=10; int &r=x; int *p=&r; *p=20; cout<
IN आउटपुट क्या है: int x=10; int &r=x; int *p=&r; *पी=20; अदालत
A
10 10
B
20 20
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) &r is the address of x (reference aliases x). *p=20 sets x=20. Output: 20.
व्याख्या (हिन्दी) &r x (संदर्भ उपनाम x) का पता है। *p=20 सेट x=20. आउटपुट: 20.
204
EN + हिं
GB What is 'placement new' in C++?
IN C++ में 'प्लेसमेंट न्यू' क्या है?
A
Allocates on stack स्टैक पर आवंटित करता है
B
Constructs object at specified memory address निर्दिष्ट मेमोरी पते पर ऑब्जेक्ट का निर्माण करता है
C
Replaces global new वैश्विक नए की जगह लेता है
D
Only for arrays केवल सरणियों के लिए
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Placement new: new(ptr) T(args) constructs object at given memory without allocation.
व्याख्या (हिन्दी) प्लेसमेंट नया: new(ptr) T(args) आवंटन के बिना दी गई मेमोरी पर ऑब्जेक्ट का निर्माण करता है।
205
EN + हिं
GB What is the output: int x=5; int *p=&x; cout<<**&p;
IN आउटपुट क्या है: int x=5; int *p=&x; अदालत
A
Address पता
B
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) &p is address of pointer p. *&p = p (the pointer). *(*&p) = *p = x = 5.
व्याख्या (हिन्दी) &p पॉइंटर पी का पता है। *&p = p (सूचक)। *(*&p) = *p = x = 5.
206
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.
व्याख्या (हिन्दी) हटाएं[] प्रत्येक तत्व के लिए विध्वंसक को कॉल करता है और सरणी को मुक्त करता है; कॉल डिस्ट्रक्टर को केवल एक बार हटाएं।
207
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).
व्याख्या (हिन्दी) डिलीट के बाद मेमोरी तक पहुंच अपरिभाषित व्यवहार (उपयोग-बाद-मुक्त) है।
208
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.
व्याख्या (हिन्दी) वाइल्ड पॉइंटर एक अप्रारंभीकृत पॉइंटर है जो मनमाने ढंग से मेमोरी स्थान को इंगित कर सकता है।
209
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।
210
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 लौटाता है।
196–210 of 1915