gpt4 book ai didi

c - 为什么下面的 do-while 循环有效?

转载 作者:太空狗 更新时间:2023-10-29 15:11:15 25 4
gpt4 key购买 nike

循环如下:

do;
while(1);

为什么上面的循环没有给出语法错误?

我正在使用 mingw gcc 编译器

最佳答案

该代码看起来像是为了混淆其含义而编写的,但如果我们查看 draft C99 standard 6.8.5 迭代语句,do while的语法是:

do statement while ( expression ) ;

and statement 可以是 expression statement 反过来又可以是 null statement 这就是 ;是。所以它与:

do
;
while(1);

我们可以从 6.8.3 Expression and null statements3 中看到:

A null statement (consisting of just a semicolon) performs no operations.

关于c - 为什么下面的 do-while 循环有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21389335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com