gpt4 book ai didi

c++ - 为什么这个嵌套 printf 语句打印 "5 53"?

转载 作者:行者123 更新时间:2023-11-30 21:40:47 25 4
gpt4 key购买 nike

#include <stdio.h>

int main() {
int x=5;
printf("%d", printf("%d %d",x,x));
}

输出5 53有人能解释一下吗?我自己尝试了一下,我认为答案应该是 5 5 2

最佳答案

printf的返回值为

number of characters transmitted to the output stream or negative value if an output error or an encoding error (for string and character conversion specifiers) occurred

(来自 here ,强调我的)和“5 5”是三个字符(即“五个空格五个”)。所以最后打印的数字是 3。

关于c++ - 为什么这个嵌套 printf 语句打印 "5 53"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31147804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com