问题
Is it possible to assign the result of a test directly to a variable?
I want to do something like
c = ( a == b )
instead of
if ( a == b )
{
c = true;
}
else
{
c = false;
}
Is this possible?
回答1:
Yes, of course.
Which you can very easily test with the compiler.
int a = 1, b = 2;
bool c = a == b;
来源:https://stackoverflow.com/questions/18183591/c-assign-test-result-directly-to-variable