previous | start | next

C Pitfalls (if you know Java or C++)

There have been several C "standards". You will likely find a few surprises:

    1   
    2   int main()
    3   {
    4      for(int i = 1; i <= 5; i++) { // ERROR
    5         printf("Hello\n");
    6      }
    7      return 0;
    8   }

Line 4 error: 'for' loop initial declaration used outside C99 mode

The loop variable must be declared before the for loop. E.g at line 4:

    1   
    2   int main()
    3   {
    4     int i;  // ERROR FIXED
    5     for(i = 1; i <= 5; i++) {
    6        printf("Hello\n");
    7     }
    8     return 0;
    9   }


previous | start | next