File Handling Online Test

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Subramani Appavupillai
S
Subramani Appavupillai
Community Contributor
Quizzes Created: 1 | Total Attempts: 257
| Attempts: 259
SettingsSettings
Please wait...
  • 1/15 Questions

     Which header file is required to use file output operations?

    • <ofstream>
    •  <ifstream>
    •  <fstream>
    • <iostream>
Please wait...
Online Test Quizzes & Trivia
About This Quiz

This File Handling Online Test assesses knowledge on file operations in C++, covering file modes, stream types, and specific functions.


Quiz Preview

  • 2. 

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

    • <ofstream>

    •  <ifstream>

    •  <fstream>

    • <iomanip>

    Correct Answer
    A.  <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?

    • Ios:trunc

    • Ios::in

    • Ios::binary

    • 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.

    • Text

    • Binary

    • ASCII

    • 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?

    • To open a file in input mode

    • To open a file in output mode

    • To truncate an existing file to half

    •  To truncate an existing file to zero

    Correct Answer
    A.  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?

    • Int

    • Char

    • Float

    • Bool

    Correct Answer
    A. 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?

    • Ios:set

    • Ios::cur

    • Ios::beg

    • 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?

    • Ios::in

    • Ios::out

    • Ios::in|ios::out

    • Ios::trunc

    Correct Answer
    A. 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?

    • Tellp()

    • Seekp()

    • Getpos()

    • 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?

    • Tellg()

    • Change()

    • Seekg()

    • Getch()

    Correct Answer
    A. 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?

    • Ios::start

    • Ios::beg

    • Ios::cur

    • Ios::first

    Correct Answer
    A. 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?

    • Setfill()

    • Setw()

    • Setwidth()

    • Setheight()

    Correct Answer
    A. 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?

    • Creating a function without having to specify the exact type

    •  creating a function with having an exact type

    • Creating a function without having blank spaces

    •  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?

    • Template parameters

    • Template type parameters

    • Template type

    •  type parameters

    Correct Answer
    A. 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.

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

    •  it will take a long time to execute

    • Duplicate code is increased

    •  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 (Updated): Mar 21, 2023 +

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.