Null 语句 (C)Null Statement (C)

“null 语句”是仅包含分号的语句;它可在需要语句时显示。A "null statement" is a statement containing only a semicolon; it can appear wherever a statement is expected. 执行 null 语句时不会发生任何事件。Nothing happens when a null statement is executed. 编码 null 语句的正确方式是:The correct way to code a null statement is:




do、for、if 和 while 等语句需要可执行语句显示为语句体。Statements such as do, for, if, and while require that an executable statement appear as the statement body. 在无需实质性语句体的情况下,null 语句可满足语法要求。The null statement satisfies the syntax requirement in cases that do not need a substantive statement body.

与任何其他 C 语句一起使用时,您可在 null 语句前包含一个标签。As with any other C statement, you can include a label before a null statement. 若要标记某个不是语句的项(如复合语句的右大括号),您可标记一个 null 语句并紧靠该项的前面插入该语句以取得相同的效果。To label an item that is not a statement, such as the closing brace of a compound statement, you can label a null statement and insert it immediately before the item to get the same effect.

以下示例阐释了 null 语句:This example illustrates the null statement:

for ( i = 0; i < 10; line[i++] = 0 )  

在此示例中,for 语句 line[i++] = 0 的循环表达式将 line 的前 10 个元素初始化为 0。In this example, the loop expression of the for statement line[i++] = 0 initializes the first 10 elements of line to 0. 由于无需任何其他语句,因此语句体为 null 语句。The statement body is a null statement, since no further statements are necessary.

请参阅See Also