내 대학에서 C 언어를 배우려면 VS Express 2012를 설치해야합니다.Visual Studio Express 2012에서 C 코드를 실행할 때의 문제
#include <stdio.h>
#include <stdlib.h>
int main() {
for (int i = 0; i <= 6; i++)
{
printf("the i value is: %d\n", i);
}
getchar();
return (0);
}
: 나는 문제없이 실행하지만이 같은 루프 "를"간단하게 작성할 때 다음 비어있는 새 프로젝트를 만들고 소스 파일 폴더에 새 항목을 추가하고
에 "Hello World"를 Source.c하는 Source.cpp 변경
이 오류를 나에게 많이 쓴다 :
------ Build started: Project: cTest, Configuration: Debug Win32 ------
Source.c
e:\ctest\source.c(7): error C2143: syntax error : missing ';' before 'type'
e:\ctest\source.c(7): error C2143: syntax error : missing ')' before 'type'
e:\ctest\source.c(7): error C2065: 'i' : undeclared identifier
e:\ctest\source.c(7): warning C4552: '<=' : operator has no effect; expected operator with side-effect
e:\ctest\source.c(7): error C2059: syntax error : ')'
e:\ctest\source.c(8): error C2143: syntax error : missing ';' before '{'
e:\ctest\source.c(9): error C2065: 'i' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
날이 문제를 해결 도와주세요. IdeOne에 표시
'i' 변수를 함수의 시작 부분에 선언하십시오. –
@AlexFarber Works. 감사. 왜 내가 루프 안에서 변수를 선언 할 수 없는지 설명 할 수 있습니까? – Luchnik
@Luchnik C에서는 임의의 범위에서 지역 변수를 선언 할 수 없지만 함수 코드 블록의 시작 부분에서만 선언 할 수 있습니다. –