C if statement
If a Boolean expression followed by a statementby the one or more statements.
grammar
If the C language syntax statements:
if(boolean_expression) { /* 如果布尔表达式为真将执行的语句 */ }
If the Boolean expression istrue, the if statement within a block of code will be executed.If the Boolean expression isfalse, if the first set of codes after the statement (after the close parenthesis) will be executed.
C language to anynon-zero and non-nullvalue is assumed to betrue,thezeroornullassumed to befalse.
flow chart
Examples
#include <stdio.h> int main () { /* 局部变量定义 */ int a = 10; /* 使用 if 语句检查布尔条件 */ if( a < 20 ) { /* 如果条件为真,则输出下面的语句 */ printf("a 小于 20\n" ); } printf("a 的值是 %d\n", a); return 0; }
When the above code is compiled and executed, it produces the following results:
a 小于 20 a 的值是 10