0

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?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Marco Frost
  • 780
  • 3
  • 12
  • 25

1 Answers1

4

Yes, of course.

Which you can very easily test with the compiler.

int a = 1, b = 2;
bool c = a == b;
H H
  • 263,252
  • 30
  • 330
  • 514