Home » C++ Programming » Files and Streams » Question
  1. What is the output of this program?
    #include <iostream>
    int main ()
    {
    int k;
    FILE * ptr;
    char buff[10];
    ptr = fopen ("Sample.txt", "w+");
    for ( k = 'A' ; k <= 'D' ; k++)
    fputc ( k, ptr);
    rewind (ptr);
    fread (buff, 1, 5, ptr);
    fclose (ptr);
    buff[3] = '\0';
    puts (buff);
    return 0;
    }
    1. ABC
    2. EFTLM
    3. ABCDE
    4. ABCD
    5. None of these
Correct Option: A

In this program, We are setting the buffer size upto 3 only, So it is printing ABC.



Your comments will be displayed only after manual approval.