The following example uses the
if-else statement to assign the value to our
result variable based on some
(x > 10) condition:
int main(void)
{
int x = 123;
int result;
if (x > 10)
{
result = 456;
}
else
{
result = 789;
}
printf("The result is: %d\n", result);
}
The similar behavior can be achieved using the
conditional expression, which has the following syntax:
(condition) ? expression1 : expression2 ...