When I compile the following code it gives compilation error that
error: ‘for’ loop initial declarations are only allowed in C99 mode for(int i = 0; i < 5; i++)and to compile your code use this option :
note: use option -std=c99 or -std=gnu99 to compile your codeNow my question is this how to use the above option and enable c99 and c11?
01 Answer
As conveyed in the error message, you should compile the code using -std=c99 or -std=gnu99. So, for example, your file is filename.c, then compile using:
gcc -std=c99 filename.cwhich will produce a binary a.out if there are no more errors. If you don't want to use this option, you can declare i before the for loop as follows:
int i;
for(i = 0; i < 5; i++)and compile it using:
gcc filename.c