CPP

CPP

Buffering has 9 Questions
Which one is always faster in writing on C++?

Writing to a file
Writing to memory
Reading from the network
None of the mentioned
What will act as a intermediate between i/o operations and physical file?

Memory
Ram
Stream buffer
None of the mentioned
How many tests are available in read and write operations?

1
2
3
4
What is the output of this program in text files?
  1.     #include 
  2.     int main ()
  3.     {
  4.         char buffer[BUFSIZ];
  5.         FILE *p1, *p2;
  6.         p1 = fopen ("myfile.txt", "w");
  7.         p2 = fopen ("myfile2.txt", "a");
  8.         setbuf ( p1 , buffer );
  9.         fputs ("Buffered stream", p1);
  10.         fflush (p1);
  11.         setbuf ( p2 , NULL );
  12.         fputs ("Unbuffered stream", p2);
  13.         fclose (p1);
  14.         fclose (p2);
  15.         return 0;
  16.     }

Buffered stream
Unbuffered stream
Error
Both a & b
What is the output of this program?
  1.     #include 
  2.     int main ()
  3.     {
  4.         FILE * p;
  5.         long size;
  6.         p = fopen ("test.txt", "rb");
  7.         if (p == NULL) 
  8.             perror ("Error opening file");
  9.         else
  10.         {
  11.             fseek (p, 0, SEEK_END); 
  12.             size = ftell (p);
  13.             fclose (p);
  14.             printf (" %ld\n", size);
  15.         }
  16.         return 0;
  17.     }

10
20
5
Depends upon the file
What is the output of this program in the file?
  1.     #include 
  2.     int main ()
  3.     {
  4.         freopen ("myfile.txt", "w", stdout);
  5.         printf ("This sentence is redirected to a file");
  6.         fclose (stdout);
  7.         return 0;
  8.     }

This sentence
This sentence is redirected
This sentence is redirected to a file
None of the mentioned
What is the output of this program in the text file?
  1.     #include 
  2.     int main ()
  3.     {
  4.         FILE * p;
  5.         char buffer[] = { 'x' , 'y' , 'z' };
  6.         p = fopen ( "myfile.txt" , "wb" );
  7.         fwrite (buffer , 1 , sizeof(buffer) , p );
  8.         fclose (p);
  9.         return 0;
  10.     }

xyz
zyx
yxz
None of the mentioned
By using which function does the buffer are automatically flushed?

fopen
copy
compare
fclose
How many parameters are available in the function setbuf?

1
2
3
4