I have encountered in some algorithm shortened syntax for the first time:
j -= i < 3;
Can you please explain to me what it means
The expression i < 3
is a boolean expression. It's either true
or false
In C++ true
and false
are implicitly convertible to the int
values 1
and 0
(respectively).
So depending on the value of i
it's either equal to
j -= 1; // i < 3 is true
or
j -= 0; // i < 3 is false
It's just a more terse way of writing:
if (i < 3)
j = j - 1;
J-=1<3 is a boolean expression . which means j=j - 1<3 . here the compiler will examine the comparison between 1 and 3 which is true . true means in c++ 1 so j=j - 1 . this expression is the same as j- -
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.