gpt4 book ai didi

c++ - 当我运行这段代码时,它输出 40,而不是 39。有人知道为什么吗?

转载 作者:行者123 更新时间:2023-11-30 02:34:53 27 4
gpt4 key购买 nike

在下面的代码中,当我运行它时,输出是40,而不是第四行的39,它不应该是39吗?我们返回 j-1 而不是 j?

int secret (int );
int another ();

double x = 10;
int const rate = 999;

int main ()
{
cout << " x first " << x << endl;
x = 70;

cout << "x second " << x << endl;
int x = 80;

cout << "x third " << x << endl;

cout << secret (x) << endl;

return 0;
}

int secret (int x)
{
int i, j;
i = x;

if (i > 10)
j = x / 2;
else
j = x / 3;

return (j-1), x/2;
}

最佳答案

只返回逗号表达式中的最后一个值。那是 x/2 == 40j-1evaluated but discarded .

关于c++ - 当我运行这段代码时,它输出 40,而不是 39。有人知道为什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34240390/

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