cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
condition
condition
Sep 11, 2012 at 6:11pm UTC
Sarah93
(32)
Hi
I faced that problem:
if i = 1, j = 2
what the following prints?:
cout << (i >= 1 && j < 4) << endl;
I tried it and the output was 1
but why???
can any one explain why?
thanks
Sep 11, 2012 at 6:15pm UTC
Moschops
(7244)
Commonly true is represented as one, and false as zero.
cout
abides by this convention when dealing with outputting boolean values. The condition
(i >= 1 && j < 4)
evaluates to true.
Last edited on
Sep 11, 2012 at 6:15pm UTC
Sep 11, 2012 at 6:16pm UTC
Disch
(13742)
true == 1
false == 0
(i >= 1 && j < 4) evaluates to true. If you cout true, it will print 1 because true == 1.
If you want it to print the words "true" and "false" instead, give it the boolalpha qualifier:
cout << boolalpha <<
true
<< endl;
Sep 11, 2012 at 6:37pm UTC
Sarah93
(32)
ahaaaaaaaaa
thank you very much
Topic archived. No new replies allowed.