在C语言中,如果指定的条件为真,则“if”语句用于有条件地执行代码块。“if”语句的基本语法如下:
if (condition) {
// code to be executed if condition is true
}
在这里,condition是一个布尔表达式,其值为true或false。如果条件为真,将执行花括号{ }内的代码。
例如:
#include <stdio.h>
int main() {
int x = 10;
if (x > 5) {
printf("x is greater than 5\n");
}
return 0;
}
这个程序会输出“x大于5”。