如果Ç与和放大器的语句;&安培; - 哪个函数会先执行呢? [英] C if statement with && - Which function will execute first?

查看:151
本文介绍了如果Ç与和放大器的语句;&安培; - 哪个函数会先执行呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个如果C语句,看起来像:

If I have an if statement in C that looks like:

if( function1() > 0 && function2() > 0 ){

    //blah

}

哪个函数将执行第一,将它始终在顺序执行?

Which function will execute first and will it always execute in that order?

推荐答案

下面功能1()是的保证的首先执行。

&放大器;&安培; 运算符是一个短路运营商函数2()甚至不会被调用,除非的结果功能1()大于零。

The && operator is a short-circuiting operator. function2() won't even be called unless the result of function1() is greater than zero.

从C99标准:

不同的是按位二进制和放大器;操作者,在&放大器;&放大器;左到右的运营商保证评价;
  还有就是第一个操作数的评估后的序列点。如果第一操作数
  进行比较等于0,第二个操作数不评估

Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated.

这篇关于如果Ç与和放大器的语句;&安培; - 哪个函数会先执行呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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