c - 什么是 C 中的空语句?

标签 c null

我想确切地知道,C语言中的null语句是什么?并解释它的典型用法。

我找到了以下代码段。

for (j=6; j>0; j++)
;

for (j=6; j>0; j++)

最佳答案

来自 msdn 页面:

The "null statement" is an expression statement with the expression missing. It is useful when the syntax of the language calls for a statement but no expression evaluation. It consists of a semicolon.

Null statements are commonly used as placeholders in iteration statements or as statements on which to place labels at the end of compound statements or functions.

了解更多:https://msdn.microsoft.com/en-us/library/1zea45ac.aspx


And explain a typical use of it.

当你想查找字符串中某个字符第一次出现的索引时

int a[50] = "lord of the rings";
int i;

for(i = 0; a[i] != 't'; i++)
    ;//null statement
//as no operation is required

关于c - 什么是 C 中的空语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40440400/

相关文章:

c - 如何使用 makefile 将变量的值附加到输出文件

c - 从管道读取信号发送

java - ImageView 空指针异常

java - 读取文本文件时出现 NullPointerException

java - 在调用 instanceof 之前是否需要检查空值?

c - 制作可变参数列表功能

C - 反向递归链表 : why use double pointer?

c - 如何在TI ccs6.0中创建自己的头文件

sql - 当您希望 NULL = NULL 为真时,在 SQL 中该怎么做?

python - 如何将空值存储为整数字段