Daily Quizzes
Mock Tests
Download MCQs Free PDF
Question
Computer Knowledge

What does the following code output?

int a = 3, b = 3;

cout << (++a == b++);

0

1

3

Compilation error 

नीचे दिए गए कोड का आउटपुट क्या है?
int a = 3, b = 3;
cout << (++a == b++);

0

1

3

समेकन की त्रुटि

View Answer & Solution
Correct Answer: A (0)
Detailed Solution:

Key Points

  • The code snippet involves pre-increment and post-increment operations on two integer variables a and b.
  • Initially, both a and b are set to 3.
  • The expression (++a == b++) is evaluated as follows:
    • ++a increments a by 1 before the comparison, so a becomes 4.
    • b++ increments b by 1 after the comparison, so b remains 3 during the comparison.
    • Thus, the comparison (4 == 3) evaluates to false (which is represented as 0 in C++).

मुख्य बातें

• इस कोड स्निपेट में दो इंटीजर वेरिएबल a और b पर प्री-इंक्रीमेंट और पोस्ट-इंक्रीमेंट ऑपरेशन शामिल हैं।

• शुरुआत में, a और b दोनों की वैल्यू 3 सेट की गई है।

• एक्सप्रेशन (++a == b++) का मूल्यांकन इस प्रकार किया जाता है:

o ++a तुलना से पहले a की वैल्यू 1 बढ़ा देता है, इसलिए a की वैल्यू 4 हो जाती है।

o b++ तुलना के बाद b की वैल्यू 1 बढ़ाता है, इसलिए तुलना के दौरान b की वैल्यू 3 ही रहती है।

o इस प्रकार, तुलना (4 == 3) का परिणाम 'फॉल्स' (गलत) होता है (जिसे C++ में 0 के रूप में दिखाया जाता है)।

India’s #1 Learning Platform
Start Complete Exam Preparation
Daily Live MasterClasses
Practice Question Bank
Mock Tests & Quizzes
Trusted by 8.1 Crore+ Students

Exam Preparation Simplified

Learn Practice Analyse Improve
Get Started Free
Download the App

Trusted by 8.1 Crore+ Students

Enquire Now

Please share a few details to view the answer and solution.

×
Illustration of two people having a discussion

We're Here for You! Get in Touch with Class24 for All Your Needs!

Disclaimer: Your privacy is important to us. We will not share your information with third parties.