什么是 C 中的空语句? [英] What is a null statement in C?

查看:97
本文介绍了什么是 C 中的空语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确切地知道,什么是 C 编程语言中的空语句?并解释它的典型用途.

I want to know exactly, what is a null statement in C programming language? And explain a typical use of it.

我找到了以下代码段.

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

并解释它的典型用途.

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

When you want to find the index of first occurrence of a certain character in a string

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

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

这篇关于什么是 C 中的空语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆