gpt4 book ai didi

c - 不理解 scanf 的返回值

转载 作者:行者123 更新时间:2023-12-01 13:40:22 25 4
gpt4 key购买 nike

我有以下 C 程序,但我不明白 scanf 的返回值。

#include <stdio.h>

int main()
{
int p,n1,n2;

p=scanf("%d %d",&n1, &n2);

printf("%d", p);
return 0;
}

p 被赋值为 scanf 的返回值。
当我为 n1n2 提供值时,p 的值始终为 2。我不明白为什么该值始终为 2,无论如何我为 n1n2 提供的数字。

最佳答案

scanf 返回读取的值的数量,在您的情况下为 2。

关于c - 不理解 scanf 的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20499675/

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