**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。
这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
16天前关闭
Improve this question的
我正在编译这段代码
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int n = get_int("How many powers of 2 do you want? ");
int power[n];
power[0] = 1;
for (int i = 1, int j = 0; i < n; i++, j++)
{
printf("%i", power[j]);
power[i] = power[i - 1] * 2;
}
}
字符串
但是这个错误出现了:
pw.c:11:21: error: expected identifier or '('
for (int i = 1, int j = 0; i < n; i++, j++)
^
型
我想问题是因为我试图在for循环中定义两个变量,但我不知道为什么。
1条答案
按热度按时间ct2axkht1#
C中逗号分隔的声明都是相同的类型,并且只有一个类型说明符:
字符串
事实上,它在
for
语句中并没有什么区别-如果你将它们声明为独立的:型
由于同样的原因无效,它应该是:
型
要有单独的类型,它们需要是单独的语句:
型
这当然在
for
语句中不起作用。