condition

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
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
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;
ahaaaaaaaaa
thank you very much
Topic archived. No new replies allowed.