更新时间:2022-10-14 21:33:40
首先, COUT
是一个C ++发明,就再也没有回C,也永远不会。
接下来,的printf
返回打印的字符数,所以第一个调用返回非零。
由于 ||
是短路布尔或,没有下面的的printf
-calls将完成
( |
是按位或,因而不短路添加,因为你所谈论的单管和@Leeor联这样的问题。)
Endresult:你好\\ n
印:5个字符+换行(将被翻译为标准输入
是文本-mode(上Unixoids身份的变换))。
7.21.6.3 printf函数
简介
的#include<&stdio.h中GT;
INT的printf(为const char *限制格式,...);
说明结果
2的printf
的功能等同于fprintf中
通过参数标准输出
插
之前的参数的printf
。结果
返回结果
3printf的
函数返回发送的字符数,或若为负值
发生输出或编码错误。
块引用>
6.5.12按位或运算符
简介结果
[...]结果
约束结果
2每个操作数应具有整数类型。结果
语义搜索
3常见的算术转换的操作数执行。结果
4的结果|
运算符是按位操作数OR(即在每个位
结果设置当且仅当至少在转换后的相应的位之一
操作数设置)。
块引用>
6.5.14逻辑或运算
简介结果
[...]结果
约束结果
2每个操作数应标量型。结果
语义搜索
3||
经营者应当产生1如果任一操作数的比较不等于0;否则,它
收益率0。结果类型INT
。结果
4不同的是按位|
运算符,||
运营商保证左到右的评价;如果
被评估的第二操作数,是使第一的评价之间的序列点
和第二操作数。如果第一操作数进行比较不等于0,第二个操作数是
没有评估。
块引用>I'm wondering what the following statement will print in C?
printf("hello\n") || (printf("goodbye\n") || printf("world\n"));
I'm usually accustomed to using "cout" to print something in C. Also I'm confused about the pipe and double pipe operators used this way. Thank you!
First,
cout
is a C++ invention, never made it back to C, and never will.Next,
printf
returns the number of printed characters, so the first call returns non-zero.As
||
is short-circuiting boolean-or, none of the followingprintf
-calls will be done.(
|
is bitwise-or, and thus not short-circuiting. Added because you are talking about single pipes and @Leeor linked such a question.)Endresult:
hello\n
is printed: 5 characters+newline (will be translated, asstdin
is text-mode (identity-transformation on Unixoids)).7.21.6.3 The printf function
Synopsis
#include <stdio.h> int printf(const char * restrict format, ...);
Description
2 Theprintf
function is equivalent tofprintf
with the argumentstdout
interposed before the arguments toprintf
.
Returns
3 Theprintf
function returns the number of characters transmitted, or a negative value if an output or encoding error occurred.
6.5.12 Bitwise inclusive OR operator
Synopsis
[...]
Constraints
2 Each of the operands shall have integer type.
Semantics
3 The usual arithmetic conversions are performed on the operands.
4 The result of the|
operator is the bitwise inclusive OR of the operands (that is, each bit in the result is set if and only if at least one of the corresponding bits in the converted operands is set).
6.5.14 Logical OR operator
Synopsis
[...]
Constraints
2 Each of the operands shall have scalar type.
Semantics
3 The||
operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0. The result has typeint
.
4 Unlike the bitwise|
operator, the||
operator guarantees left-to-right evaluation; if the second operand is evaluated, there is a sequence point between the evaluations of the first and second operands. If the first operand compares unequal to 0, the second operand is not evaluated.