Conditional Operator
cond ? a : b is a short if expression.
Example
#include <stdio.h>
int main(void) {
int a = 7, b = 3;
int max = a > b ? a : b;
printf("%d %s\n", max, a % 2 ? "odd" : "even");
return 0;
}Result
7 odd
Exercise
Ternary symbol.
x > 0 1 : 0
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.