简体   繁体   English

在C中的变量声明上获取语法错误

[英]Getting a syntax error on a variable declaration in C

I see a syntax error when I run the debugger on the two variables I declare in CLion. 当我在CLion中声明的两个变量上运行调试器时,看到语法错误。 I commented the debugger errors it shows me in the lines of the two variables. 我评论了在两个变量行中显示的调试器错误。

int sum3or5Multiples() {

    int sum = 0;    // sum: error: A syntax error in expression, near `/mt sum`.
    int multipleOf3;    // multipleOf3: error: A syntax error in expression, near `/mt multipleOf3`
    for (multipleOf3 = 0; multipleOf3 < 1000; multipleOf3 + 3) {
        sum = sum + multipleOf3;
    }
    int multipleOf5;
    for (multipleOf5 = 0; multipleOf5 < 1000; multipleOf5 + 5) {
        sum = sum + multipleOf5;
        if ((3 * multipleOf5) < 1000) {
            sum = sum - (3 * multipleOf5);
        }
    }
    return sum;
}

It seems you mean 看来你是说

multipleOf3 += 3

and

multipleOf5 += 5

instead of 代替

multipleOf3 + 3

and

multipleOf5 + 5

With these changes the function compiles without errors. 通过这些更改,函数可以编译而不会出错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM