Sail E0 Webinar
Question
Does this compile without error?
int main()
{
for (int k = 0; k < 10; k++);
return 0;
}
Options:
A .  Yes
B .  No
C .  Depends on the C standard implemented by compilers
D .  None of the mentioned
Answer: Option C


Compilers implementing C90 does not allow this but compilers implementing C99 allow it.
Output:
$ cc pgm4.c
pgm4.c: In function 'main':
pgm4.c:4: error: 'for' loop initial declarations are only allowed in C99 mode
pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers