I begin leaning C language.
I run program then errror: "Declaration is not allowed here
Thanks!Code:#include<stdio.h> #include<conio.h> main() { clrscr(); int n; printf("Input n: "); scanf("%d",&n); getch(); }
I begin leaning C language.
I run program then errror: "Declaration is not allowed here
Thanks!Code:#include<stdio.h> #include<conio.h> main() { clrscr(); int n; printf("Input n: "); scanf("%d",&n); getch(); }
Local variables (such as 'int n' in your example) should always occur at the beginning of the block. Move your declaration of 'n' to before your call to clrscr().
This may only be the case in older versions of the C standard which is why joybanerjee39 is not receiving an error because of it, don't remember though.
Additionally, main should be declared as 'int main( void )' and should return 0, until you know better.
Thanks........................
Yes variables must be at the start of a block except in C99
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"