Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 2 : -1 / -1
Advertisement
Detailed Solution
सही उत्तर -1 / -1 है।
Key Points
Helpful?
Question:
What is the output of the following C++ code? `cout << (-7 % 3);` / निम्नलिखित C++ कोड का आउटपुट क्या होगा? `cout << (-7 % 3);`
1.
2 / 2
2.
-1 / -1
3.
1 / 1
4.
-2 / -2
Correct Answer: -1 / -1
Since C++11 (and C99), integer division truncates toward zero, so `-7 / 3` is `-2` with remainder `-1`; the sign of `%` follows the dividend. The trap option (a) assumes a mathematical (floored) modulo giving 2. / C++11 (और C99) से integer division शून्य की ओर truncate होता है, अतः `-7 / 3` है `-2` और शेषफल `-1`; `%` का चिह्न भाज्य (dividend) का अनुसरण करता है। जाल विकल्प (a) गणितीय (floored) modulo मानकर 2 देता है।
Downloaded from PrepSnap (prepsnap.in)