Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

C judgment


May 11, 2021 C


Table of contents


C Judgment

The judgment structure requires the programmer to specify one or more conditions to evaluate or test, as well as statements to execute when the condition is true (required) and statements to execute when the condition is false (optional).

The C language assumes any values that are not zero and non-empty as true and zero or null as false.

Here is a general form of judgment structure typical of most programming languages:

C judgment



Judgment statement

The C language provides the following types of judgment statements. Click on the link to see the details of each statement.

Statement describe
IF statement one IF statement Composed with one or more statements by a Boolean expression.
IF ... ELSE statement one IF statement After you can follow an optional ELSE statement The ELSE statement is executed in the Boolean expression.
Nested IF statement You can be in one if or else if Use another in the statement if or else if Scriptures.
SWITCH statement one switch The statement allows for testing a variable equal to multiple values.
Nested Switch statement You can be in one switch Use another in the statement switch Scriptures.

? : Operator

We've covered the conditional operator ? , which can be used instead of if... E lse statement. Its general form is as follows:

Exp1 ? Exp2 : Exp3;

Exp1, Exp2, and Exp3 are expressions. Note the use and location of the colon.

? T he value of the expression is determined by Exp1. I f Exp1 is true, the value of Exp2 is calculated and the result is the entire ? T he value of the expression. I f Exp1 is false, the value of Exp3 is calculated, and the result is the entire ? The value of the expression.