Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 44
Q701:
What does the operator + (double d) function do?
A. Adds a matrix to a matrix
B. Adds a scalar to each element in the matrix
C. Subtracts a scalar from the matrix
D. Multiplies matrix with a scalar
Correct Answer:
B
Chapter: 44
Q702:
How does the input(istream &is) function interact with the user?
A. It prompts the user for input
B. It reads from a file
C. It outputs to the console
D. It writes to a file
Correct Answer:
A
Chapter: 44
Q703:
What is the default constructor of the Matrix class?
A. Initializes rows to zero
B. Initializes columns to zero
C. Initializes both rows and columns to zero
D. Does nothing
Correct Answer:
C
Chapter: 45
Q704:
What does the assignment operator function return in the Matrix class?
A. A pointer to a matrix
B. A reference to a matrix
C. A copy of the matrix
D. A constant value
Correct Answer:
B
Chapter: 45
Q705:
Why is the assignment operator function marked as const?
A. To allow modifications
B. To prevent assignment to the returned reference
C. To increase efficiency
D. To simplify the code
Correct Answer:
B
Chapter: 45
Q706:
What is the purpose of checking if( &m != this) in the assignment operator?
A. To prevent memory leaks
B. To check if matrices are equal
C. To prevent self-assignment
D. To optimize memory usage
Correct Answer:
C
Chapter: 45
Q707:
What happens if the number of rows and columns in the matrices are not the same in the assignment operator?
A. Nothing happens
B. The matrix on the left is resized
C. An error is thrown
D. The program crashes
Correct Answer:
B
Chapter: 45
Q708:
In the addition operator, what is returned after adding two matrices?
A. A reference to the new matrix
B. A new matrix
C. The sum of elements
D. A pointer to the new matrix
Correct Answer:
B
Chapter: 45
Q709:
What is the primary difference between a + d and d + a in the context of matrix operations?
A. No difference
B. They produce different results
C. Only a + d is valid
D. Only d + a is valid
Correct Answer:
B
Chapter: 45
Q710:
What does the multiplication operator function check before multiplying two matrices?
A. If matrices have the same size
B. If matrices are conformable for multiplication
C. If the matrices are identical
D. If the result will be a square matrix
Correct Answer:
B
Chapter: 45
Q711:
What is the role of temp in the multiplication operator function?
A. It stores intermediate results
B. It is the final result matrix
C. It stores the original matrix
D. It is used to check conformity
Correct Answer:
B
Chapter: 45
Q712:
Why should division by zero be checked in matrix operations?
A. To optimize the code
B. To prevent runtime errors
C. To increase efficiency
D. To ensure matrices are conformable
Correct Answer:
B
Chapter: 45
Q713:
What type of function is Matrix operator + (double d, Matrix &m)?
A. Member function
B. Friend function
C. Inline function
D. Static function
Correct Answer:
B
Chapter: 45
Q714:
What happens if division by zero is detected in a matrix operation?
A. An exception is thrown
B. The original matrix is returned
C. The program crashes
D. A zero matrix is returned
Correct Answer:
B
Chapter: 45
Q715:
How is the += operator different from the + operator in matrix operations?
A. += does not change a
B. += changes a
C. + does not perform checks
D. + operator is faster
Correct Answer:
B
Chapter: 45
Q716:
In the context of object-oriented programming, what is encapsulation?
A. Combining data and code
B. Separating data and code
C. Writing short code
D. Optimizing code
Correct Answer:
A
Chapter: 45
Q717:
What does the stream extraction (>>) operator do in the Matrix class?
A. Writes matrix to a file
B. Reads matrix from a file
C. Reads matrix from the keyboard
D. Writes matrix to the screen
Correct Answer:
C
Chapter: 45
Q718:
Why is the multiplication operator considered the most complicated in matrix operations?
A. It involves addition
B. It requires checking conformity
C. It changes the original matrices
D. It produces a new matrix
Correct Answer:
B