In Java, the standard "for loop" is that the counter i is declared inside the loop as follows:
for (int i=0; i < 10; i++){
System.out.println("Hello, world!");
}
However, for C, if you try to declare the counter inside the for for loop:
for (int it=0; i<10;i++{
printf("Hello, world!\n");
}
You may get this error:
for_loop_test.c: In function ‘main’:
for_loop_test.c:4: error: ‘for’ loop initial declaration used outside C99 mode
By default, the compiler gcc uses the ANSI c syntax (aka C89 mode), not ISO syntax (aka C99 mode). To turn on the C90 mode, add this argument to gcc
gcc -std=c99 foo.c
Note:
ANSI < American National Standard Institute
ISO < International Standard Organization
No comments:
Post a Comment