c++ - "value-based"OR 运算符的通用术语

标签 c++ c perl language-agnostic

一个简单的问题

 printf("%d", 99 || 44) prints "1" in C
 print 99 || 44 prints "99" in perl

有两种不同的评价。每一个都有名字吗?

编辑:我很想知道与 C 相比,通常如何调用 Perl 求值。当您说“C 示例是 X,而 perl 示例不是 X,而是 Y”时,您会使用哪些词来表示 X 和Y.“短路”不是我要找的。

最佳答案

阅读here .

Binary || performs a short-circuit logical OR operation. That is, if the left operand is true, the right operand is not even evaluated. Scalar or list context propagates down to the right operand if it is evaluated.

In Perl the || and && operators differ from C's in that, rather than returning 0 or 1, they return the last value evaluated.


printf("%d", 99 || 44) prints "1" in C

那是因为 99||44 返回 true(由于 || 的短路 Action ,只有 99(非零)被评估)其等效于 1 因此 printf() 打印 1

print 99 || 44 prints "99" in perl

..不是返回 0 或 1,而是返回最后计算的值(此处为 99)。

关于c++ - "value-based"OR 运算符的通用术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2172448/

相关文章:

c - malloc 的奇怪行为

c - malloc和realloc的关系,当内存中没有所需的空间时如何处理

regex - 如何使用注释创建正则表达式搜索和替换?

c++ - 在 Visual Studio 2013 Express 中为具有不规则扩展名(例如 .tpp)的 C++ 文件启用 IntelliSense

c++ - Code::Blocks 调试器在 Kubuntu 上运行缓慢

c++ - git 克隆器的项目依赖

linux - Bash AWK 找到多个模式并分配给不同的变量

c++ - 二进制数据注入(inject)字符串

c - C排序问题中的双向链表

perl - 如何在 Windows 的后台运行 Perl 脚本?