Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q591: What is the return type of the overloaded stream insertion operator (<<)?
  • A: int
  • B: void
  • C: ostream&
  • D: istream&
View Answer
C

Q592: Which type of operator cannot be overloaded as a member function when dealing with streams?
  • A: Unary operators
  • B: Binary operators
  • C: Stream insertion (<<) and extraction (>>) operators
  • D: Arithmetic operators
View Answer
C

Q593: In the context of operator overloading, which parameter is always passed by reference for operator >>?
  • A: The first parameter
  • B: The second parameter
  • C: Both parameters
  • D: Neither parameter
View Answer
B

Q594: Why are ostream and istream objects passed by reference to the overloaded operators?
  • A: To allow modification of their state
  • B: To avoid copying large objects
  • C: To maintain cascading operations
  • D: To provide direct access to their internal data
View Answer
C

Q595: What must be done if you want to overload operator << for a class?
  • A: Declare it as a member function
  • B: Define it inside the class without any special declaration
  • C: Define it as a non-member function and declare it as a friend of the class
  • D: Use it as a global function without any special declaration
View Answer
C

Q596: What is a typical use of the operator >> function in a class?
  • A: To output the class's data to the console
  • B: To read input from a stream and modify the class's data
  • C: To perform arithmetic operations on the class's data
  • D: To format and display the class's data
View Answer
B

Q597: In the Matrix class example, what does the operator >> function do?
  • A: Outputs the matrix data to the console
  • B: Inputs matrix data from the console
  • C: Adds two matrices together
  • D: Displays the matrix with formatting
View Answer
B

Q598: What does the operator << function do in the Matrix class?
  • A: Modifies the matrix's internal state
  • B: Outputs the matrix data with formatting
  • C: Inputs the matrix data from the user
  • D: Performs matrix multiplication
View Answer
B

Q599: Why is it important to pass the matrix object by reference in the operator >> function?
  • A: To ensure the function does not modify the matrix
  • B: To ensure the matrix object is copied for efficiency
  • C: To allow the function to modify the matrix object
  • D: To prevent the matrix object from being passed at all
View Answer
C

Q600: What does a user-defined manipulator typically return?
  • A: A string
  • B: An integer
  • C: A reference to ostream
  • D: A reference to istream
View Answer
C

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now