Test Series - cpp

Test Number 77/102

Q: What is Valarray in C++?
A. Container for efficient operations on an array
B. Container for efficient printing of the array
C. Container for efficient value conversion of array
D. Container for efficient type conversion of array
Solution: Valarray is a special container provided by C++ to hold and perform mathematical operations on array efficiently.
Q: Which of the following is correct about Valarray?
A. Supports element-wise mathematical operations
B. Slower than a normal array
C. Harder to use
D. Can have only integer Valarrays
Solution: Valarray is good at performing mathematical operations. Also, Valarray supports element-wise mathematical operations. They are easier to use and can be of any type.
Q: Which header file is required for using Valarray?
A. 
B. 
C. 
D. 
Solution:  header file is required to use the functionalities of Valarrays.
Q: What is the use of apply() function in Valarray?
A. Returns new array after shifting elements by the given number
B. Returns the summation of all elements of the Valarray
C. Applies the manipulation provided to all the elements of the array
D. Returns new array after circular shifting elements by the given number
Solution:  header provides apply() function to apply any manipulation passed to the function to all the elements in the Valarray.
Q: What is the use of sum() function in Valarray?
A. Applies the manipulation provided to all the elements of the array
B. Returns the summation of all elements of Valarray
C. Returns new array after shifting elements by the given number
D. Returns new array after circular shifting elements by the given number
Solution:  header provides sum() function to sum all the elements in the Valarray and returns the total sum.
Q: What is the function of shift()?
A. Applies the manipulation provided to all the elements of the array
B. Returns the summation of all elements of Valarray
C. Returns new array after shifting elements by the given number
D. Returns new array after circular shifting elements by the given number
Solution:  header provides shift() function to shift all the elements of the Valarray by a given number either to the left or to the right.
Q: Which of the following is correct about the shift?
A. Returns new array after shifting elements by the given number
B. Shifts the elements towards left if the argument supplied is positive
C. Shifts the elements towards the right if the argument supplied is negative
D. All of the mentioned
Solution: shift() function is used to shift all the elements of the Valarray by a given number. the elements are shifted towards left if the number if positive and towards the right if the number if negative.
Q: Which of the following is correct about shift() and cshift()?

1) shift() makes some values of Valarray equal to 0 after shifting by a non-zero number
2) cshift() makes some values of Valarray equal to 0 after shifting by a non-zero number
A. 2 only
B. 1 only
C. Both 1 and 2
D. Neither 1 nor 2
Solution: After shifting by some non-zero number the shift() function makes some elements of Valarray equal to zero whereas cshift() does no such things.
Q: Which function is used to swap two Valarray?
A. max()
B. min()
C. swap()
D. change()
Solution:  header provides swap() function to swap two Valarrays.
Q: Which function is used to print the maximum element from Valarray?
A. change()
B. min()
C. swap()
D. max()
Solution:  header provides max() function to print the maximum element from Valarray.

You Have Score    /10