- conditional operator, inline if; iif, ternary if, ternary operator
- 조건부 연산자, 비교 선택 연산자, 3항 연산자, 삼항 연산자
- ? :
C
#include <stdio.h>
int main()
{
int a = 2, b = 1;
int max = a > b ? a : b;
printf("%d\n", max);
}
Java
int max;
int a = 1;
int b = 2;
max = (a > b) ? a : b;
System.out.println(max);
JavaScript
console.log( "The fee is " + (isMember ? "$2.00" : "$10.00") );
PHP
$score = 50;
$grade = $score > 80 ? 'A' : 'B';
echo $grade;
# B
Python
score = 50
grade = 'A' if score > 80 else 'B'
print( grade )
# B
Ruby
puts 1 == 2 ? "true" : "false"
# false