File Handling Online Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Subramani Appavupillai
S
Subramani Appavupillai
Community Contributor
Quizzes Created: 1 | Total Attempts: 248
Questions: 15 | Attempts: 248

SettingsSettingsSettings
Online Test Quizzes & Trivia

C++ Online Test


Questions and Answers
  • 1. 

     Which header file is required to use file output operations?

    • A.

      <ofstream>

    • B.

       <ifstream>

    • C.

       <fstream>

    • D.

      <iostream>

    Correct Answer
    A. <ofstream>
    Explanation
    The header file is required to use file output operations. This header file provides the necessary functions and classes for writing data to files. It includes the ofstream class, which is used to create output file streams and perform output operations on them. By including this header file, we can access the necessary functionality for writing data to files in our program.

    Rate this question:

  • 2. 

    Which of the following is used to create a stream that performs both input and output operations?

    • A.

      <ofstream>

    • B.

       <ifstream>

    • C.

       <fstream>

    • D.

      <iomanip>

    Correct Answer
    C.  <fstream>
    Explanation
    The correct answer is . This is because is a C++ library that allows for both input and output operations on files. It provides the functionality to create a stream that can read from and write to a file simultaneously. The other options, and , are used for either output or input operations respectively. is a library used for manipulating input/output formatting.

    Rate this question:

  • 3. 

    Which of the following is not used as a file opening mode?

    • A.

      Ios:trunc

    • B.

      Ios::in

    • C.

      Ios::binary

    • D.

      Ios::ate

    Correct Answer
    A. Ios:trunc
    Explanation
    The option "ios:trunc" is not used as a file opening mode. This is because "ios:trunc" is not a valid file opening mode in C++ or any programming language. The correct file opening modes in C++ are "ios::in", "ios::out", "ios::app", "ios::ate", and "ios::binary".

    Rate this question:

  • 4. 

    By default, all the files in C++ are opened in _________ mode.

    • A.

      Text

    • B.

      Binary

    • C.

      ASCII

    • D.

      VTC

    Correct Answer
    A. Text
    Explanation
    In C++, by default, all files are opened in "Text" mode. This means that the file is treated as a text file, where characters are represented using their ASCII values. This mode allows for easy reading and writing of text data to and from the file. Other modes, such as "Binary" or "ASCII", may be used when dealing with non-textual data or specific encoding formats. However, in the absence of any specified mode, the default is "Text" mode.

    Rate this question:

  • 5. 

     What is the use of ios::trunc mode?

    • A.

      To open a file in input mode

    • B.

      To open a file in output mode

    • C.

      To truncate an existing file to half

    • D.

       To truncate an existing file to zero

    Correct Answer
    D.  To truncate an existing file to zero
    Explanation
    The ios::trunc mode is used to truncate an existing file to zero. This means that when a file is opened in this mode, it will delete all the contents of the file and make it empty. This can be useful in situations where we want to start writing new data to a file from scratch, without any previous content.

    Rate this question:

  • 6. 

    What is the return type open() method?

    • A.

      Int

    • B.

      Char

    • C.

      Float

    • D.

      Bool

    Correct Answer
    D. Bool
    Explanation
    The return type of the open() method is bool, which stands for boolean. This means that the open() method will return either true or false. A boolean value is commonly used to indicate the success or failure of an operation. In the context of the open() method, it is likely that a true value would indicate that the file or resource was successfully opened, while a false value would indicate that the operation was unsuccessful.

    Rate this question:

  • 7. 

    Which of the following is not used to seek file pointer?

    • A.

      Ios:set

    • B.

      Ios::cur

    • C.

      Ios::beg

    • D.

      Ios::end

    Correct Answer
    A. Ios:set
    Explanation
    The "ios:set" option is not used to seek the file pointer. The other options, "ios::cur", "ios::beg", and "ios::end" are used to seek the file pointer to the current position, the beginning of the file, and the end of the file, respectively. However, "ios:set" is not a valid option for seeking the file pointer.

    Rate this question:

  • 8. 

     Which of the following is the default mode of the opening using the fstream class?

    • A.

      Ios::in

    • B.

      Ios::out

    • C.

      Ios::in|ios::out

    • D.

      Ios::trunc

    Correct Answer
    C. Ios::in|ios::out
    Explanation
    The default mode of opening using the fstream class is ios::in|ios::out. This mode allows both input and output operations on the file.

    Rate this question:

  • 9. 

    Which function is used in C++ to get the current position of file pointer in a file?

    • A.

      Tellp()

    • B.

      Seekp()

    • C.

      Getpos()

    • D.

      Showpos()

    Correct Answer
    A. Tellp()
    Explanation
    The tellp() function is used in C++ to get the current position of the file pointer in a file. It returns the current position as a streampos object, which represents the position in the stream. This function is typically used with file streams to determine the current position before performing any read or write operations.

    Rate this question:

  • 10. 

    Which function is used to reposition the file pointer?

    • A.

      Tellg()

    • B.

      Change()

    • C.

      Seekg()

    • D.

      Getch()

    Correct Answer
    C. Seekg()
    Explanation
    The seekg() function is used to reposition the file pointer. It allows us to move the file pointer to a specific position within the file, which can be useful when we want to read or write data at a specific location. The tellg() function is used to get the current position of the file pointer. The change() and getch() functions are not related to repositioning the file pointer.

    Rate this question:

  • 11. 

    Which of the following is used to move the file pointer to start of a file?

    • A.

      Ios::start

    • B.

      Ios::beg

    • C.

      Ios::cur

    • D.

      Ios::first

    Correct Answer
    B. Ios::beg
    Explanation
    The option "ios::beg" is used to move the file pointer to the start of a file. This is a flag in the ios class that represents the beginning of a file. By using this flag, the file pointer is set to the beginning of the file, allowing operations to be performed from the start.

    Rate this question:

  • 12. 

     Which function allows you to set minimum width for the next input?

    • A.

      Setfill()

    • B.

      Setw()

    • C.

      Setwidth()

    • D.

      Setheight()

    Correct Answer
    B. Setw()
    Explanation
    The function setw() allows you to set the minimum width for the next input. This function is commonly used in C++ programming to specify the minimum number of characters to be written in the output. It is often used in combination with the

    Rate this question:

  • 13. 

     What is a function template?

    • A.

      Creating a function without having to specify the exact type

    • B.

       creating a function with having an exact type

    • C.

      Creating a function without having blank spaces

    • D.

       creating a function without class

    Correct Answer
    A. Creating a function without having to specify the exact type
    Explanation
    A function template allows the creation of a function without specifying the exact type that it will operate on. This means that the function can be written in a generic way, allowing it to work with different types of data. It provides flexibility and reusability in code, as the same function template can be used with different types of arguments. The exact type is determined when the function is called, based on the argument provided.

    Rate this question:

  • 14. 

    Which is used to describe the function using placeholder types?

    • A.

      Template parameters

    • B.

      Template type parameters

    • C.

      Template type

    • D.

       type parameters

    Correct Answer
    B. Template type parameters
    Explanation
    Template type parameters are used to describe the function using placeholder types. These parameters allow the function to accept different data types as arguments, without the need to specify the exact type beforehand. By using template type parameters, the function becomes more flexible and can be used with various data types, providing a generic solution.

    Rate this question:

  • 15. 

     Pick out the correct statement.

    • A.

      You only need to write one function, and it will work with many different types

    • B.

       it will take a long time to execute

    • C.

      Duplicate code is increased

    • D.

       it will take a long time to execute & duplicate code is increased

    Correct Answer
    A. You only need to write one function, and it will work with many different types
    Explanation
    The correct statement is "you only need to write one function, and it will work with many different types." This means that by writing just one function, you can handle multiple types of inputs, making the code more efficient and reusable. It eliminates the need to write separate functions for each type, reducing code duplication and making the program easier to maintain.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 28, 2020
    Quiz Created by
    Subramani Appavupillai
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.