简体   繁体   English

将 printf 语句分配给 int 变量

[英]Assigning a printf statement to a int variable

See the following code:请参阅以下代码:

int i={
          printf("c" "++")
       };

it prints c++ and returns 3 to i.它打印 c++ 并将 3 返回给 i。 how it is assigning 3 to i?它是如何将 3 分配给 i 的? need explanation!需要解释!

printf returns the number of bytes written to stdout . printf返回写入stdout的字节数。 "c++" is exactly three bytes long (not counting the null-terminator). "c++"正好是三个字节长(不包括空终止符)。

By the way, you really don't need to use the curly braces, you can simply do int i=printf("c" "++");顺便说一句,你真的不需要使用花括号,你可以简单地做int i=printf("c" "++"); . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM