C memory managmentBasics
Ternary
Ternary in c
a > b ? a : b
The entire line is a single expression that evaluates to one value. Here's how it works:
- a > b is the condition
- a is the final value if the condition is true
- b is the final value if the condition is false
- The entire expression (a > b ? a : b) evaluates to either a or b, which is then assigned to max in our example.
- Ternaries are a way to write a simple if/else statement in one line.
#include <stdio.h>
int main() {
int tern = 1 == 0 ? 't' : 'f';
printf("%c\n", tern);
return 0;
}