Visual C++中未声明的标识符C编程

tur*_*rnt 4 c visual-studio-2010 visual-c++

所以我正在创建一个简单的程序,我通常使用GNU编译器.

但是,这次我选择使用Visual C++在C中进行开发.

我已正确设置项目,更改设置以使其在C中编译.代码非常简单:

#include <stdlib.h>
#include <stdio.h>

int main(){

    printf("Hey!");
    int x = 9;
    printf("%d",x);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我使用Code :: Blocks IDE和GNU编译器编译它,它可以工作,但由于某种原因它在Visual C++中不起作用.我一直收到这些错误:

error C2143: syntax error : missing ';' before 'type'

error C2065: 'x' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

ild*_*arn 10

VC++ 2010只实现了C89/C90,而不是在函数体内部的其他语句之后允许变量声明的新C标准.要修复它,请将声明x移到以下的开头main:

#include <stdlib.h>
#include <stdio.h>

int main() {
    int x = 9;
    printf("Hey!");
    printf("%d",x);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)