C++ MCQs - Tuple

This section focuses on the "Tuple" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which statement is true about tuple?

A. A tuple is an object that can hold a number of elements.
B. The elements can be of different data types.
C. The elements of tuples are initialized as arguments in order in which they will be accessed.
D. All of the above

View Answer


2. What will be output for the following code?

#include<iostream> 
#include<tuple>
using namespace std; 
int main() 
{ 
    tuple <char,int,float> geek(20,'g',17.5); 
    cout << ""The size of tuple is : ""; 
    cout << tuple_size<decltype(geek)>::value << endl; 
    return 0; 
  
} 

A. The size of tuple is : 3
B. The size of tuple is : 4
C. The size of tuple is : 5
D. The size of tuple is : 6

View Answer


3. Which function concatenates two tuples and returns a new tuple?

A. tie
B. tuple_cat
C. tuple_con
D. concat

View Answer


4. Which returns the number of elements present in the tuple?

A. tie
B. size
C. tuple_size
D. size_tuple

View Answer


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

View Answer


6. How many variants of tie() function is there?

A. 1
B. 2
C. 3
D. 4

View Answer


7. ___________ word is used to ignore the unpacking of some elements of a tuple.

A. stop
B. ignore
C. cancel
D. remain

View Answer


8. What will be output for the following code?

#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
 tuple <int, char, string> tp;
 tp = make_tuple(""Hello"", 4, 'c');
 return 0;
}

A. Nothing is printed
B. Compile-time error
C. Run-time error
D. Exception occurs

View Answer


9. 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;

View Answer


10. make_tuple function is used for?

A. used to access the tuple values and modify them
B. used to assign tuple with values
C. used to returns the number of elements present in the tuple
D. None of the above

View Answer





Discussion



* You must be logged in to add comment.