C:有"懒惰的评价"在使用和放大器;&安培;运算符,如C ++? [英] C : is there "lazy evaluation" when using && operator, as in C++?

查看:115
本文介绍了C:有"懒惰的评价"在使用和放大器;&安培;运算符,如C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这看起来是正确的:

i would like to know if this looks correct :

while((next !=NULL) && (strcmp(next->name, some_string) < 0) {
    //some process
}

我的意思是,如果下一个是NULL,则除权pression的第二部分将不会被永远编译器进行测试?我听说在C ++中它的情况下(但我什至不知道它)。

i mean, if next is NULL, then the second part of the expression won't be ever tested by the compiler ? i have heard that in C++ it's the case (but i'm not even sure of it).

有人可以证实我,我不会得到一些编译器奇怪的错误与?

Can someone confirm me that i won't get strange errors on some compilers with that ?

推荐答案

&放大器;&安培; 短路,你使用了正确的结果。如果接下来 NULL 字符串比较不会发生。

Yes && is short circuited and you are using it correctly.
If next is NULL string compare will never happen.

这篇关于C:有&QUOT;懒惰的评价&QUOT;在使用和放大器;&安培;运算符,如C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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