C:如果解释(退出(0),0){} code线 [英] C: explain if(exit(0),0){} line of code

查看:149
本文介绍了C:如果解释(退出(0),0){} code线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习C和作为练习,我试着写一个简单的程序,没有任何分号。我有一些麻烦替换返回0 语句,但我发现,这是办法做到这一点在C(唯一):如果(退出(0),0){}

I am learning C and as an exercise, I'm trying to write a simple program without any semicolons. I've had some trouble with replacing return 0 statement but I've found that this is (the only?) way to do it in C: if(exit(0),0){}.

是如何执行这一说法的工作?

How exactly does this statement work?

我知道退出() STDLIB 是一个无效的功能,但我不明白什么 0 部分的如果作品(其余的我很清楚)。

I know that exit() from stdlib is a void function but I don't understand what the ,0 part in the if works (the rest is clear to me).

推荐答案

经营者使用C会评估它的参数,返回第二个值。所以前pression

The , operator in C evaluates both its arguments, and returns the value of the second one. So the expression

exit(0), 0

通话退出(0)键,返回0所以,code你贴实际上相当于:

calls exit(0) and returns 0. So the code you posted is effectively equivalent to:

exit(0);
if (0) {}

然而,退出()应终止该进程,所以这应该从来没有真正回来。这个成语只是被用来prevent虚假编译器警告。

However, exit() should terminate the process, so this should never actually return. The idiom is just being used to prevent spurious compiler warnings.

这篇关于C:如果解释(退出(0),0){} code线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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