C if 语句

C 语言教程 · 2019-02-20 07:29:33

一个 if 语句 由一个布尔表达式后跟一个或多个语句组成。

语法

C 语言中 if 语句的语法:

if(boolean_expression)
{
   /* 如果布尔表达式为真将执行的语句 */
}

如果布尔表达式为 true,则 if 语句内的代码块将被执行。如果布尔表达式为 false,则 if 语句结束后的第一组代码(闭括号后)将被执行。

C 语言把任何非零非空的值假定为 true,把null 假定为 false

流程图

C 中的 if 语句

实例

实例

#include <stdio.h> int main () { /* 局部变量定义 */ int a = 10; /* 使用 if 语句检查布尔条件 */ if( a < 20 ) { /* 如果条件为真,则输出下面的语句 */ printf("a 小于 20\n" ); } printf("a 的值是 %d\n", a); return 0; }

当上面的代码被编译和执行时,它会产生下列结果:

a 小于 20
a 的值是 10

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Information

The Information

James Gleick / Vintage / 2012-3-6 / USD 16.95

James Gleick, the author of the best sellers Chaos and Genius, now brings us a work just as astonishing and masterly: a revelatory chronicle and meditation that shows how information has become th......一起来看看 《The Information》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具