gpt4 book ai didi

c - 在 C 中返回和操作返回值

转载 作者:太空宇宙 更新时间:2023-11-04 01:14:06 24 4
gpt4 key购买 nike

我很难理解 C 处理返回值的方式。比如说我们有:

int one = 0; 
one = foo(); // Why isn't one being assigned 10?
// Clearly there is a difference between these two
printf("%d", one); // one is still 0
printf("%d", foo());

int foo()
{
return 10;
}

我似乎无法阐明为什么存在差异,以及为什么一个不能优于另一个。

谢谢!

最佳答案

以下程序的输出是 1010。我用 gcc -Wall -std=c99 main.c -o main.exe 编译了它 所以,我认为这要么是你的编译器问题,要么你声称 printf("% d", one); 打印零。

#include <stdio.h>

int foo(void);

int main()
{
int one = 0;
one = foo();

printf("%d", one);
printf("%d", foo());

return 0;
}

int foo()
{
return 10;
}

关于c - 在 C 中返回和操作返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5613519/

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