Data Structures and Algorithms — MCQ Practice

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

📚 1018 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
1018 questions
571
EN + हिं Medium
GB std::mutex::lock() blocks until:
IN std::mutex::lock() तब तक ब्लॉक रहता है:
A
Always returns हमेशा लौटता है
B
Mutex is acquired (other thread releases it) म्यूटेक्स का अधिग्रहण कर लिया गया है (अन्य थ्रेड इसे जारी करता है)
C
Timer expires टाइमर समाप्त हो रहा है
D
Thread terminates धागा समाप्त हो जाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) lock() waits until mutex is available.
व्याख्या (हिन्दी) लॉक() म्यूटेक्स उपलब्ध होने तक प्रतीक्षा करता है।
572
EN + हिं Medium
GB std::try_lock() differs from lock() in:
IN std::try_lock() लॉक() से भिन्न है:
A
Same behavior वही व्यवहार
B
try_lock returns immediately (true if acquired, false if not) Try_lock तुरंत लौटाता है (यदि प्राप्त हुआ तो सही, नहीं तो गलत)
C
try_lock blocks ट्राई_लॉक ब्लॉक
D
try_lock throws ट्राई_लॉक फेंकता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) try_lock: non-blocking attempt to acquire mutex.
व्याख्या (हिन्दी) प्रयास_लॉक: म्यूटेक्स प्राप्त करने का गैर-अवरुद्ध प्रयास।
573
EN + हिं
GB The output of: mutex m; int x=0; thread t([&]{lock_guard lg(m); x=42;}); t.join(); cout<
IN का आउटपुट: म्यूटेक्स एम; int x=0; थ्रेड t([&]{lock_guard lg(m); x=42;}); टी.जुड़ें(); अदालत
B
42 42
C
Error गलती
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Thread safely sets x=42 under mutex; main reads 42.
व्याख्या (हिन्दी) थ्रेड सुरक्षित रूप से म्यूटेक्स के अंतर्गत x=42 सेट करता है; मुख्य पाठ 42.
574
EN + हिं Medium
GB Condition variable wait(lock, predicate) returns when:
IN कंडीशन वेरिएबल wait(lock, predicate) तब लौटता है जब:
A
Always immediately हमेशा तुरंत
B
Predicate returns true (spurious wakeups handled) विधेय सत्य लौटाता है (नकली वेकअप संभाला गया)
C
Mutex unlocks म्यूटेक्स अनलॉक हो जाता है
D
Thread signals थ्रेड सिग्नल
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) wait releases lock, waits for notification, rechecks predicate.
व्याख्या (हिन्दी) प्रतीक्षा लॉक जारी करती है, अधिसूचना की प्रतीक्षा करती है, विधेय की पुनः जाँच करती है।
575
EN + हिं Medium
GB std::call_once guarantees:
IN std::call_once गारंटी:
A
Function called multiple times फ़ंक्शन को कई बार कॉल किया गया
B
Function called exactly once across all threads फ़ंक्शन सभी थ्रेड्स में बिल्कुल एक बार कॉल किया जाता है
C
Per-thread call प्रति-थ्रेड कॉल
D
No guarantee कोई गारंटी नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Exactly one thread executes the function.
व्याख्या (हिन्दी) बिल्कुल एक थ्रेड फ़ंक्शन निष्पादित करता है।
576
EN + हिं
GB What is the output: promise p; future f=p.get_future(); thread t([&p]{p.set_value(42);}); t.join(); cout<
IN आउटपुट क्या है: वादा पी; भविष्य f=p.get_future(); थ्रेड t([&p]{p.set_value(42);}); टी.जुड़ें(); अदालत
B
42 42
C
Error गलती
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Promise sets value; future.get() receives it.
व्याख्या (हिन्दी) वादा मूल्य निर्धारित करता है; Future.get() इसे प्राप्त करता है।
577
EN + हिं
GB The output of: auto f=async(launch::async,[]{return 42;}); cout<
IN का आउटपुट: auto f=async(launch::async,[]{return 42;}); अदालत
B
42 42
C
Error गलती
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) async runs lambda in thread; f.get() returns 42.
व्याख्या (हिन्दी) async थ्रेड में लैम्ब्डा चलाता है; f.get() 42 लौटाता है।
578
EN + हिं
GB The output of: packaged_task pt([](){return 99;}); auto f=pt.get_future(); pt(); cout<
IN इसका आउटपुट: packaged_task pt([](){return 99;}); ऑटो f=pt.get_future(); पीटी(); अदालत
B
99 99
C
Error गलती
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) packaged_task wraps callable; invoke it; get result via future.
व्याख्या (हिन्दी) पैकेज्ड_टास्क कॉल करने योग्य रैप्स; इसका आह्वान करें; भविष्य के माध्यम से परिणाम प्राप्त करें।
579
EN + हिं
GB What is the output: int x=5; auto f=[x=x*2]{return x;}; cout<
IN आउटपुट क्या है: int x=5; ऑटो f=[x=x*2]{रिटर्न x;}; अदालत
A
5 5
B
10 10
C
Error गलती
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Init capture x=x*2=10; lambda returns 10.
व्याख्या (हिन्दी) इनिट कैप्चर x=x*2=10; लैम्ब्डा रिटर्न 10.
580
EN + हिं Medium
GB Init captures in C++14 lambda [y=expr]:
IN C++14 लैम्ब्डा में Init कैप्चर [y=expr]:
A
Capture y by name y को नाम से पकड़ें
B
Capture and initialize new variable y with expr एक्सपीआर के साथ नए वेरिएबल y को कैप्चर और इनिशियलाइज़ करें
C
Copy capture कैप्चर कॉपी करें
D
Reference capture संदर्भ कैप्चर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) [y = expr] creates new variable y inside lambda.
व्याख्या (हिन्दी) [y = expr] लैम्ब्डा के अंदर नया वेरिएबल y बनाता है।
581
EN + हिं
GB The output of: auto f=[i=0]()mutable{return i++;}; cout<
IN इसका आउटपुट: auto f=[i=0]()mutable{return i++;}; अदालत
A
000 000
B
012 012
C
123 123
D
Error गलती
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Mutable lambda with init capture; i goes 0,1,2.
व्याख्या (हिन्दी) इनिट कैप्चर के साथ म्यूटेबल लैम्ब्डा; मैं 0,1,2 जाता हूँ।
582
EN + हिं
GB What is the output: vector v(10); iota(v.begin(),v.end(),1); auto sum=reduce(execution::par,v.begin(),v.end()); cout<
IN आउटपुट क्या है: वेक्टर v(10); iota(v.begin(),v.end(),1); स्वत: योग=कम(निष्पादन::बराबर,v.begin(),v.end()); अदालत
A
55 55
B
45 45
C
50 50
D
Error गलती
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+...+10=55 (parallel reduce).
व्याख्या (हिन्दी) 1+2+...+10=55 (समानांतर घटाएँ)।
583
EN + हिं
GB The output of: auto v=views::iota(6)|views::filter([](int x){return x%2!=0;}) |views::transform([](int x){return x*x;}); for(auto x:v)cout<
IN का आउटपुट: auto v=views::iota(6)|views::filter([](int x){return x%2!=0;}) |views::transform([](int x){return x*x;}); for(ऑटो x:v)cout
A
1 9 25 1 9 25
B
4 16 4 16
C
1 4 9 16 25 1 4 9 16 25
D
Error गलती
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Odd numbers {1,3,5} squared: {1,9,25}.
व्याख्या (हिन्दी) विषम संख्याएं {1,3,5} वर्ग: {1,9,25}।
584
EN + हिं
GB The output of: namespace A{int x=1;} namespace B{int x=2;} cout<
IN इसका आउटपुट: नेमस्पेस A{int x=1;} नेमस्पेस B{int x=2;} कोउट
A
12 12
B
21 21
C
11 11
D
22 22
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::x=1, B::x=2.
व्याख्या (हिन्दी) ए::x=1, बी::x=2.
585
EN + हिं
GB The output of: namespace A{void f(){cout<<"A";}} namespace B{void f(){cout<<"B";}} using namespace A; f();
IN इसका आउटपुट: नेमस्पेस A{void f(){cout
A
A
B
B बी
C
Error गलती
D
AB अब
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) using namespace A brings f into scope; calls A::f.
व्याख्या (हिन्दी) नेमस्पेस ए का उपयोग एफ को दायरे में लाता है; ए::एफ को कॉल करता है।
571–585 of 1018