Home / CSE MCQs / C-MCQs :: Discussion

Discussion :: C-MCQs

  1. Does this compile without error?

    int main()
    {
    for (int k = 0; k < 10; k++);
    return 0;
    }
  2. A.
    Yes
    B.
    No
    C.
    Depends on the C standard implemented by compilers
    D.
    None of the mentioned

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    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


Be The First To Comment