Top

Discussion

Does this compile without error?

int main()
{
for (int k = 0; k < 10> return 0;
}

  • A.Yes
  • B.No
  • C.Depends on the C standard implemented by compilers
  • D.None of the mentioned

Answer: 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

No comment is present. Be the first to comment.
Loading…

Post your comment