Test Series - cpp

Test Number 75/102

Q: What are the tuples in C++?
A. Objects that can hold more than one element of different types
B. Objects that can hold a single element of complex type
C. Objects that can hold more than one element of the same types
D. Objects that can hold a single element of fundamental type
Solution: Object that can hold more than one elements having different types. For example, an object holding int, float and char types.
Q: Which of the following is correct about tuples?
A. A tuple can hold more than one element
B. A tuple can hold elements having different types
C. Elements of tuples are initialized in order
D. All of the mentioned
Solution: A tuple can hold more than one element of different types. The order of initialization must be the same as the order of declaration.
Q: Which header file is required to use tuples in your program?
A. 
B. 
C. 
D. 
Solution:  header file is required to use tuples in your program. This header file contains all the related functions about tuples.
Q: Which of the following is the correct way of declaring a tuple?
A. tuple tp;
B. tuple tp = new tuple;
C. tuple tp;
D. Tuple tp;
Solution: The correct syntax of declaring tuple is tuple  tp; Lowercase tuple is used to declare to tuples therefore Tuple  tp; is wrong.
Q: Which of the following function is used to initialize a tuple?
A. make()
B. make_pair()
C. make_tuple()
D. make_Tuple()
Solution: make_tuple() function is available under the header file which is used to initialize a tuple.
Q: What is the use of get() function in tuples?
A. To access an element of a tuple
B. To print an element of a tuple
C. To check whether the element of the tuple is empty
D. To delete an element
Solution: get() function is provided with header file to access an element of a tuple.
Q: Which of the following is correct about tuple_size?
A. Returns the number of elements in a tuple
B. Returns the maximum sized type element
C. Returns the total number of bits used by the tuple
D. Returns the sum of non-string values
Solution: tuple_size is used to get the number of elements inside a tuple. For example the tuple_size of tp = {1, 4, “hello”} is 3.
Q: Which of the following is correct about swap()?
A. Swaps first element of both tuples
B. Swaps two tuples
C. Swaps elements of a tuple alternatively
D. Swaps last elements of two tuples
Solution: swap() function is used to swap two tuples. For example t1 = {1,2} and t2 = {‘a’,’b’} then after swapping both the tuples becomes t1 = {‘a’,’b’} and t2 = {1,2}.
Q: Which word is used to stop the unpacking of a value in a tuple?
A. stop
B. ignore
C. cancel
D. remain
Solution: Ignore word is used to ignore the unpacking of some elements of a tuple.
Q: What is the use of tuple_cat() function?
A. Takes the union of two tuples
B. Takes the intersection of two tuples
C. Concatenates two tuples
D. Removes elements of the second tuple from first
Solution: tuple_cat() function of is used to concatenate two tuples. The new tuple will contain all the elements of both the tuples.

You Have Score    /10