Home / CSE MCQs / C-MCQs :: Discussion

Discussion :: C-MCQs

  1. Comment on the output of this C code?

    int main()
    {
    char c;
    int i = 0;
    FILE *file;
    file = fopen("test.txt", "w+");
    fprintf(file, "%c", 'a');
    fprintf(file, "%c", -1);
    fprintf(file, "%c", 'b');
    fclose(file);
    file = fopen("test.txt", "r");
    while ((c = fgetc(file)) != -1)
    printf("%c", c);
    return 0;
    }
  2. A.
    a
    B.
    Infinite loop
    C.
    Depends on what fgetc returns
    D.
    Depends on the compiler

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    None.
    Output:
    $ cc pgm3.c
    $ a.out
    a


Be The First To Comment