Examveda

What will be the output of the following C++ code in text files?
#include <stdio.h>
int main ()
{
    char buffer[BUFSIZ];
    FILE *p1, *p2;
    p1 = fopen ("myfile.txt", "w");
    p2 = fopen ("myfile2.txt", "a");
    setbuf ( p1 , buffer );
    fputs ("Buffered stream", p1);
    fflush (p1);
    setbuf ( p2 , NULL );
    fputs ("Unbuffered stream", p2);
    fclose (p1);
    fclose (p2);
    return 0;
}

A. Buffered stream

B. Unbuffered stream

C. Error

D. Buffered & Unbuffered stream

Answer: Option D


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it