I have a great experience of C++, and now I'm trying to do some things in pure C. But I noticed a really strange fact.
The following code:
#include <stdio.h>
int main()
{
double a;
scanf_s("%lf", &a);
double b;
b = a + 1;
printf("%lf", b);
return 0;
}
compiles OK in sourceLair (with gcc compiler, as well as I know), but generates following errors in Microsoft Visual Studio (with Visual C++):
1>Task 1.c(8): error C2143: syntax error : missing ';' before 'type'
1>Task 1.c(9): error C2065: b: undeclared identifier
1>Task 1.c(9): warning C4244: =: conversion from 'double' to 'int', possible loss of data
1>Task 1.c(11): error C2065: b: undeclared identifier
I experimented a bit with the code and noticed that placing a variable declaration before calling any function is OK, but placing a declaration after it results in compilation error.
So what's wrong? I use a fresh installation of Microsoft Visual Studio 2012 Express with no settings changed.