gpt4 book ai didi

c - 新手 : C syntax error when compiling

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

    for(int a = 0, b = 1; b < n; a++; b++)
{
if (compare(values[a], values[b]))
counter++;
else
{
int x = values[a];
values[a] = values[b];
values[b] = x;
}
}

当我尝试编译时,第一行 [for(int...] 出现此错误:

helpers.c:68:41: error: expected ')' before ';' token

为什么我需要添加另一个 ')'?

最佳答案

for(int a = 0, b = 1; b < n; a++; b++)
^
|
problem

for 循环的末尾需要一个逗号 (,) 而不是分号 (;) ab:

for(int a = 0, b = 1; b < n; a++, b++)
^

这是 comma operator .

这两个 SO 问题也可能有帮助:How do I put two increment statements in a C++ 'for' loop?What is the full "for" loop syntax in C (and others in case they are compatible)?

关于c - 新手 : C syntax error when compiling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11299789/

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