-3

Can somebody tell me what does the following expression mean in a C code?

A = B < C ? B:C;

I know that it's an if-else condition, but don't know it works. I will appreciate if somebody wrote it in simple if else conditions.

Don't have reputation to comment/feedback or appreciate.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Asad Ali
  • 25
  • 6

1 Answers1

0

You can translate it to the following:

if (B < C)
    A = B;
else
    A = C;

This is called a ternary operator (or in C# conditional operator).

It returns the value after the question mark if the condition is true and otherwise returns the value after the colon:

condition ? ReturnedIfConditionIsTrue : ReturnedIfConditionIsFalse
MetaColon
  • 2,895
  • 3
  • 16
  • 38