The comma operator (,) allows you to view multiple expressions where only one sentence is permitted. The comma operator checks the left operator, then the right operator, and returns the result of the correct operand.
First, the left-hand operator is tested, magnifying x from 1 to 2. Next, the right-hand operator is tested, which rises by 2 to 3. printed later in the console.
Conditional operator (? Because historically, it was only a C ++ ternary operator, it is sometimes referred to as a "ternary operator."
The ?: operator provides a shorthand method for doing a particular type of if/else statement. Would you please review lesson 4.10 -- Introduction to if statements if you need a brush up on if/else before proceeding?
if (status) statement1; other statement2;
If the condition checks to be valid, then expression1 is performed. Otherwise, expression2 is performed. Note that expression2 is not an option.
Consider an if / else statement that looks like this:
|