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
为什么我需要添加另一个')'?
答案 0 :(得分:11)
for(int a = 0, b = 1; b < n; a++; b++)
^
|
problem
您需要在,
- 循环的末尾添加逗号(;
)而不是分号(for
),其中a
和{{1} }}:
b
这两个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)?