In C language, ?: is a conditional operator, also known as the ternary operator, which can select between two values based on a conditional Boolean expression. The syntax is: condition ? value_if_true : value_if_false. If condition is true, returns value_if_true, otherwise returns value_if_false.
#What is ?: in C language?
In C language, ?: is a conditional operator, also known as the ternary operator. It allows developers to choose between two different values based on a conditional Boolean expression.
Syntax
?: The syntax of the operator is as follows:
<code class="c">condition ? value_if_true : value_if_false;</code>
where:
How it works
?: The operator is based on the true or false value of the condition Boolean expression, in value_if_true## Choose between # and value_if_false.
Example
Here is an example of using the ?: operator:<code class="c">int age = 18; char *message = (age >= 18) ? "成年人" : "未成年人";</code>
age Whether it is greater than or equal to 18, choose between the string "Adult" and "Minor". Since age is greater than or equal to 18, message will be assigned the value "Adult".
The above is the detailed content of What is ?: in c language?. For more information, please follow other related articles on the PHP Chinese website!