Question

In C++, which of the following numbers will evaluate to ture when used in the condition...

In C++, which of the following numbers will evaluate to ture when used in the condition of an if statement:

a. 1

b. -1

c. 100

d. Al of the above

Note : Please provide a solution

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is d. All of the above

Reasion : Becouse non zero integers are evaluated as true.

// Here is the code and output which shows the proof.

#include <iostream>
using namespace std;

int main(){
   if(1)
       cout<<" 1 is evaluated true"<<endl;
   else
       cout<<" 1 is evaluated false"<<endl;

   if(-1)
       cout<<" -1 is evaluated true"<<endl;
   else
       cout<<" -1 is evaluated false"<<endl;

   if(100)
       cout<<" 100 is evaluated true"<<endl;
   else
       cout<<" 100 is evaluated false"<<endl;

   return 0;
}

//////============ output =================//CAwindows system32\cmd.exe 1 is eỤaluated true -1 is evaluatedtrue 100 is evaluated true Press апч keч to continue

Add a comment
Know the answer?
Add Answer to:
In C++, which of the following numbers will evaluate to ture when used in the condition...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT