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
1
EN + हिं
GB What is the output: int x=10; 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 dereferences pointer to x; *p=20 sets x=20.
व्याख्या (हिन्दी) *p सूचक को x से संदर्भित करता है; *p=20 सेट x=20.
2
EN + हिं
GB What is a 'dangling pointer'?
IN 'लटकता सूचक' क्या है?
A
Pointer to freed/destroyed memory मुक्त/नष्ट की गई स्मृति का सूचक
B
Null pointer नल पॉइंटर
C
Void pointer शून्य सूचक
D
Pointer to stack ढेर करने के लिए सूचक
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A dangling pointer points to memory that has been freed or gone out of scope, causing UB if dereferenced.
व्याख्या (हिन्दी) एक लटकता हुआ सूचक उस मेमोरी की ओर इशारा करता है जो मुक्त हो गई है या दायरे से बाहर हो गई है, जिससे डीरेफ़रेंस होने पर यूबी उत्पन्न होता है।
3
EN + हिं
GB What is the output: int a=1,b=2; int *p=&a; p=&b; *p=10; cout<
IN आउटपुट क्या है: int a=1,b=2; int *p=&a; पी=&बी; *पी=10; अदालत
A
1 10 1 10
B
10 10 10 10
C
1 2 1 2
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is reassigned to &b. *p=10 sets b=10. a is unchanged. Output: 110.
व्याख्या (हिन्दी) p को &b को पुनः सौंपा गया है। *पी=10 सेट बी=10. ए अपरिवर्तित है. आउटपुट: 110.
4
EN + हिं
GB What is the output: int x=5; int *p=nullptr; cout<<(p==nullptr);
IN आउटपुट क्या है: int x=5; int *p=nullptr; अदालत
B
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is null; p==nullptr is true=1.
व्याख्या (हिन्दी) पी शून्य है; p==nullptr सत्य=1 है।
5
EN + हिं
GB What is 'pointer arithmetic' in C++?
IN C++ में 'पॉइंटर अंकगणित' क्या है?
A
Adding integers to pointers to navigate arrays सरणियों को नेविगेट करने के लिए पॉइंटर्स में पूर्णांक जोड़ना
B
Arithmetic on pointer values as integers पूर्णांकों के रूप में सूचक मानों पर अंकगणित
C
Only valid for void pointers केवल शून्य सूचकों के लिए मान्य है
D
A compile error एक संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Pointer arithmetic (p+n) moves pointer by n*sizeof(*p) bytes, valid within array bounds.
व्याख्या (हिन्दी) पॉइंटर अंकगणित (p+n) पॉइंटर को n*sizeof(*p) बाइट्स द्वारा ले जाता है, जो सरणी सीमाओं के भीतर मान्य है।
6
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.
7
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 रिटर्न मिलता है।
8
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.
व्याख्या (हिन्दी) स्मार्ट पॉइंटर्स (यूनिक_पीटीआर, शेयर्ड_पीटीआर, वीक_पीटीआर) आरएआईआई के माध्यम से हीप मेमोरी को स्वचालित रूप से प्रबंधित करते हैं।
9
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 कॉन्स्ट पॉइंटर के माध्यम से संशोधित करने का प्रयास करता है: संकलन त्रुटि।
10
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 वे जो इंगित करते हैं उसे स्वैप करता है - नहीं, यह पॉइंटर्स को स्वयं स्वैप करता है। अदालत
11
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**) दूसरे पॉइंटर का पता संग्रहीत करता है।
12
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) अनिर्दिष्ट/अपरिभाषित व्यवहार है।
13
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.
14
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) आवंटन के बिना दी गई मेमोरी पर ऑब्जेक्ट का निर्माण करता है।
15
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.
1–15 of 127