printf函数`语义(" ...")||的printf(QUOT; ...")||的printf(QUOT; ...")` [英] Semantics of `printf("…") || printf("…") || printf("…")`

查看:153
本文介绍了printf函数`语义(" ...")||的printf(QUOT; ...")||的printf(QUOT; ...")`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么下面的语句将用C打印?

 的printf(你好\\ N)|| (输出(再见\\ n)||的printf(世界\\ n));

我通常习惯用COUT来打印C.东西我也很困惑,用这样的方式管和双管运营。谢谢!


解决方案

首先, 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 。结果
  返回结果
  3 printf的函数返回发送的字符数,或若为负值
  发生输出或编码错误。



  

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 following printf-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, as stdin 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 The printf function is equivalent to fprintf with the argument stdout interposed before the arguments to printf.
Returns
3 The printf 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 type int.
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.

这篇关于printf函数`语义(&QUOT; ...&QUOT;)||的printf(QUOT; ...&QUOT;)||的printf(QUOT; ...&QUOT;)`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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