प्रोग्रामिङ – Programming MCQ
प्रोग्रामिङ – कम्प्युटर र IT
Programming · Computer & IT (Technical) · १,५६५ प्रश्न
१,५६५ प्रश्न उपलब्ध। मोड छान्नुहोस्:
प्रोग्रामिङ: प्रश्न र उत्तर
सही लागेको विकल्पमा थिच्नुहोस्। सही भए हरियो, गलत भए रातो देखिन्छ; ३ सेकेन्डपछि सही उत्तर र व्याख्या देखिन्छ।
सही: ० / ०
-
Trace this C++ fragment and give its output: set<int> s = {3, 1, 3, 2}; cout << s.size();
सही उत्तर: ख) 3
std::set stores only unique values, so the duplicate 3 is ignored and the size is 3.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Trace this C++ fragment and give its output: map<string, int> m; m["b"] = 2; m["a"] = 1; cout << m.begin()->first;
सही उत्तर: क) a
std::map keeps its keys in sorted order, so the first element has key "a".
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Trace this C++ fragment and give its output: vector<int> v(3, 5); cout << v.size() << v[2];
सही उत्तर: घ) 35
vector<int> v(3, 5) creates 3 elements, each equal to 5, so it prints 3 then 5.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In C++, given template <class T> T mx(T a, T b) { return a > b ? a : b; }, what is printed by cout << mx(3, 7) << mx('a', 'z'); ?
सही उत्तर: ग) 7z
The template is instantiated for int and for char; the larger values are 7 and 'z', printed as 7z.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In C++, struct A has static int count, incremented in its constructor and decremented in its destructor (count starts at 0). What is printed by: { A a; { A b; } cout << A::count; } ?
सही उत्तर: ख) 1
b is destroyed when its inner block ends, so only a is alive when count is printed: 1.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
In C++, with the overloads int f(int a) { return a * 2; } and double f(double a) { return a / 2; }, what is printed by cout << f(4) << " " << f(4.0); ?
सही उत्तर: क) 8 2
f(4) calls the int version (4 * 2 = 8) and f(4.0) calls the double version (4.0 / 2 = 2.0), which cout prints as 2.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Trace this C++ fragment and give its output: string s = "abc"; s += "de"; cout << s.length();
सही उत्तर: घ) 5
After appending, s is "abcde", whose length is 5 (std::string does not count a terminating null).
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Trace this C++ fragment and give its output: int x = 5; int &r = x; r++; cout << x;
सही उत्तर: ग) 6
r is a reference (another name) for x, so incrementing r increments x to 6.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Given int f(void) { static int x = 10; return x--; }, what is printed by: int a = f(); int b = f(); printf("%d %d", a, b); ?
सही उत्तर: ख) 10 9
The static variable keeps its value between calls; the first call returns 10 (then x becomes 9), the second returns 9.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
-
Given int count(char *s) { return *s ? 1 + count(s + 1) : 0; }, what does count("Nepal") return?
सही उत्तर: क) 5
The function adds 1 for each character until the terminating '\0', so it returns the string length, 5.
💬 टिप्पणी / गल्ती रिपोर्ट (०)
यी अभ्यास प्रश्न हुन्, आधिकारिक प्रश्न होइनन्। पाठ्यक्रम, विज्ञापन र नतिजाका लागि सम्बन्धित निकायको आधिकारिक वेबसाइट हेर्नुहोस्। उत्तरमा गल्ती भेटे प्रश्नमुनिको "टिप्पणी / गल्ती रिपोर्ट" मा लेख्नुहोस्।
नमस्ते! पाठ्यक्रम, सामान्य ज्ञान, भाषा परीक्षा वा कुनै प्रश्नको उत्तर बुझ्न सोध्नुहोस्।
AI ले गल्ती गर्न सक्छ। महत्वपूर्ण कुरा आधिकारिक स्रोतमा जाँच्नुहोस्।