C++ Programming MCQ (Multiple Choice Questions) - SchoolingAxis

C++ Programming MCQ (Multiple Choice Questions)

 Que- Which operator is used to access the first or second element of a pair? 

a. -> 

b. . 

c. * 

d. [] 


Answer- . 


Que- Which of the following is the correct syntax of accessing the first element of a pair p? 

a. p.first 

b. p.second 

c. p[0] 

d. p[1] 


Answer- p.first 


Que- Which of the following is the correct syntax of accessing the second element of a pair p? 

a. p.first 

b. p.second 

c. p[0] 

d. p[1] 


Answer- p.second 


Que- What happens if a pair is not initialized? 

a. Both first and second part is initialized to zero or null 

b. Both first and second part is initialized a garbage value 

c. First is initialized to zero or null and second is initialized a garbage value 

d. Second is initialized to zero or null and first is initialized a garbage value 


Answer- Both first and second part is initialized to zero or null 


Que- Which of the following Operator cannot be used with pairs? 

a. + 

b. == 

c. = 

d. != 


Answer- + 


Que- What is any in C++? 

a. STL container used to store a single value of any type 

b. Exception class in C++ 

c. Fundamental type provided by C++ 

d. Template data type 


Answer- STL container used to store a single value of any type 


Que- In how many different ways any-container can be constructed? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which of the following syntax is used to convert any variable to its original type? 

a. any_cast<variable_name>(); 

b. any_cast(variable_name); 

c. <original_type>(variable_name); 

d. any_cast<original_type>(variable_name); 


Answer- any_cast<original_type>(variable_name); 


Que- Which header file is required to use any container? 

a. <any> 

b. <stl> 

c. <container-any> 

d. <containers> 


Answer- <any> 


Que- Which exception is thrown if the typecasting is not done properly? 

a. bad_type_cast 

b. bad_any_cast 

c. type_mismatched 

d. bad_cast_mismatched 


Answer- bad_any_cast 


Que- What is the use of emplace() function? 

a. Used to change the object any container is holding 

b. Used to add more item to the any list 

c. Used to empty any container value 

d. Used to check the type of any variable 


Answer- Used to change the object any container is holding 


Que- What is the use of type() function in any container? 

a. Used to destroys the contained object in any variable 

b. Used to change the object any container is holding 

c. Used to return the type information about the any container 

d. Used to check whether a container is empty or not 


Answer- Used to return the type information about the any container 


Que- What is the use of has_value() function in any container? 

a. Used to destroys the contained object in any variable 

b. Used to change the object any container is holding 

c. Used to return the type information about the any container 

d. Used to check whether any container is empty or not 


Answer- Used to check whether any container is empty or not 


Que- What is the use of reset() function? 

a. Used to destroys the contained object in any variable 

b. Used to change the object any container is holding 

c. Used to empty any container value 

d. Used to check the type of any variable 


Answer- Used to destroys the contained object in any variable 


Que- In how many ways we can handle errors in any class? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which type of heap is implemented in STL heap? 

a. max heap 

b. min heap 

c. middle heap 

d. close heap 


Answer- max heap 


Que- Which function is used to construct heap from given sequence of numbers? 

a. create_heap() 

b. make_heap() 

c. construct_heap() 

d. start_heap() 


Answer- make_heap() 


Que- What is the use of front() function in heap? 

a. Returns the element closest to the median of a sequence 

b. Returns the last element of the heap 

c. Returns the first element of the heap 

d. Returns the element closest to mean of a sequence 


Answer- Returns the first element of the heap 


Que- Which function is used to insert an element into heap? 

a. push_back() 

b. push_heap() 

c. pop_back() 

d. pop_heap() 


Answer- push_heap() 


Que- Elements in STL heap are removed in ________________________ 

a. decreasing order 

b. increasing order 

c. alternate i.e. once max element then min element 

d. input order 


Answer- decreasing order 


Que- Which header file is required to use heap in your program? 

a. <heap> 

b. <algorithm> 

c. <vector> 

d. <map> 


Answer- <algorithm> 


Que- Which of the following is correct syntax of making heap from a vector v? 

a. make_heap(v.elements); 

b. make_heap(v); 

c. make_heap(v.end(), v.begin()); 

d. make_heap(v.begin(), v.end()); 


Answer- make_heap(v.begin(), v.end()); 


Que- What is the use of sort_heap() function in heap? 

a. To sort the elements in the heap into descending order 

b. To sort the elements in the heap into ascending order 

c. To sort the first half of the heap 

d. To sort the second half of the heap 


Answer- To sort the elements in the heap into ascending order 


Que- Which function is used to check whether a given sequence is heap or not? 

a. sort_heap() 

b. is_heap() 

c. is_heap_until() 

d. check_heap() 


Answer- is_heap() 


Que- What is the use of is_heap_until() function? 

a. Returns the iterator of the last element of the sequence always 

b. Returns the iterator to the position from where the sequence is a heap 

c. Returns the iterator of the position till that the sequence is a heap 

d. Returns the iterator of the first element of the sequence 


Answer- Returns the iterator of the position till that the sequence is a heap 


Que- What is vtable in C++? 

a. Lookup table to resolve function calls in dynamic manners 

b. Lookup table to resolve function calls in static manners 

c. Lookup table to see which are the functions available for calls throughout the program 

d. Lookup table to check how many functions are there int he program 


Answer- Lookup table to resolve function calls in dynamic manners 


Que- Which classes can have vtable? 

a. Classes having friend functions 

b. Classes having virtual functions 

c. Classes having static functions 

d. All classes have a vtable 


Answer- Classes having virtual functions 


Que- What is the full form of vtable? 

a. V type table 

b. Vector table 

c. Virtual table 

d. Virtual-vector table 


Answer- Virtual table 


Que- What is vptr? 

a. A hidden pointer in a class that points to a virtual table of that class 

b. A hidden pointer in a class that points to virtual functions of that class 

c. A hidden pointer in a class that points to virtual members of the class of that class 

d. A pointer in a class that points to other class 


Answer- A hidden pointer in a class that points to a virtual table of that class 


Que- What is the full form of vptr? 

a. Vector Pointer 

b. Virtual Pointer 

c. V type Pointer 

d. Virtual-vector Pointer 


Answer- Vector Pointer 


Que- vptr is _______________ 

a. a real pointer 

b. like this pointer of class 

c. passed as a parameter to all functions of class 

d. used to resolve self-references 


Answer- a real pointer 


Que- What are the Generators in C++? 

a. An object that generates uniformly distributed numbers 

b. An object that generates a number from a given sequence 

c. An object that generates the smallest number from a given range 

d. An object that generates unique numbers 


Answer- An object that generates uniformly distributed numbers 


Que- What are Distributions in C++? 

a. Objects that converts a sequence into a sequence having an ascending order 

b. Objects that converts a sequence into a sequence having specific random variable distribution 

c. Objects that converts a sequence into a sequence having a descending order 

d. Objects that converts a sequence into a sequence having only the smallest, largest and median 


Answer- Objects that converts a sequence into a sequence having specific random variable distribution 


Que- Which header file is used for generating random numbers? 

a. <gen_dist> 

b. <distribution> 

c. <generator> 

d. <random> 


Answer- <random> 


Que- What is Pseudo-random number engines? 

a. Uses user input for random number generation 

b. Uses an algorithm that does not require any initial seed to generate random numbers 

c. Uses initial seed based algorithm to generate random numbers 

d. Random number generates depends on the program 


Answer- Uses initial seed based algorithm to generate random numbers 


Que- How many Pseudo-random number engines are there? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- What are different operations are used in Pseudo-random number engines? 

a. operator() 

b. min() 

c. max() 

d. all of the mentioned 


Answer- all of the mentioned 


Que- What is a Random number generator? 

a. A generator that generates deterministic random numbers 

b. A generator that generates both non-deterministic random numbers and deterministic random numbers 

c. A generator that generates non-deterministic random numbers 

d. A generator that generates a simple random number 


Answer- A generator that generates non-deterministic random numbers 


Que- What is random_device? 

a. A pseudo-random number generator 

b. Time-dependent random number generator 

c. Simple random number generator 

d. A true random number generator 


Answer- A true random number generator 


Que- Which algorithm is used in subtract_with_carry_engine? 

a. Mersenne Twister algorithm 

b. Lagged fibonacci generator algorithm 

c. Either the Mersenne Twister algorithm or Lagged fibonacci generator algorithm 

d. Fibonacci generator 


Answer- Lagged fibonacci generator algorithm 


Que- What is the default random engine? 

a. Random number engine that generates pseudo-random numbers 

b. Mersenne Twister 19937 generator generating 32-bit true random number 

c. Random number engine that generates true random numbers 

d. Mersenne Twister 19937 generator generating 32-bit pseudo random number 


Answer- Random number engine that generates pseudo-random numbers 


Que- What are Engine Adaptors? 

a. Class template that adopts a pseudo-random number generator engine 

b. Class template that adopts a pseudo-random number generator engine to produce numbers with a given numbers of bits 

c. Random number engine that generates pseudo-random numbers 

d. Mersenne Twister 19937 generator generating 32-bit true random number 


Answer- Class template that adopts a pseudo-random number generator engine to produce numbers with a given numbers of bits 


Que- How many Engine Adaptors are there in C++? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which of the header file is used for array type manipulation? 

a. <array> 

b. <type_traits> 

c. <iostream> 

d. std namespace 


Answer- std namespace 


Que- What is the use of is_array() function in C++? 

a. To check if a variable is array type or not 

b. To check if a variable is 1-D array type or not 

c. To check if a variable is 2-D array type or not 

d. To check if a variable is 1-D or 2-D array type or not 


Answer- To check if a variable is array type or not 


Que- What is the use of is_same() function in C++? 

a. To check if a variable is array type or not 

b. To check whether two variables have the same characteristics 

c. To check if two variable is of array type or not 

d. To check whether two variables are different or not 


Answer- To check whether two variables have the same characteristics 


Que- What is the use of rank() function in C++? 

a. Returns size of each dimension 

b. Returns how many total elements can be stored in an array 

c. Returns how many elements are in array currently 

d. Returns the dimension of an array 


Answer- Returns the dimension of an array 


Que- Which of the following is correct about extent() function? 

a. Returns how many elements are in array currently 

b. Returns the size of the 1st dimension 

c. Returns how many total elements can be stored in an array 

d. Returns the size of a given dimension 


Answer- Returns the size of a given dimension 


Que- Which of the following is correct about remove_extent() function? 

a. Removes the given dimension from an array 

b. Removes the first dimension from the right of the array 

c. Removes the first dimension from the left of the array 

d. Removes the last dimension from the left of the array 


Answer- Removes the first dimension from the left of the array 


Que- Which of the following is correct about remove_all_extents() function? 

a. Removes the all dimension from an array 

b. Removes the first dimension from the left of the array 

c. Removes the first dimension from the right of the array 

d. Removes the last dimension from the left of the array 


Answer- Removes the all dimension from an array 


Que- 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 


Answer- Objects that can hold more than one element of different types 


Que- 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 


Answer- All of the mentioned 


Que- Which header file is required to use tuples in your program? 

a. <stl> 

b. <array> 

c. <slgorithm> 

d. <tuple> 


Answer- <tuple> 


Que- Which of the following is the correct way of declaring a tuple? 

a. tuple tp<type1, type2, type3>; 

b. tuple tp = new tuple<type1, type2, type3>; 

c. tuple <type1, type2, type3> tp; 

d. Tuple <type1, type2, type3> tp; 


Answer- tuple <type1, type2, type3> tp; 


Que- Which of the following function is used to initialize a tuple? 

a. make() 

b. make_pair() 

c. make_tuple() 

d. make_Tuple() 


Answer- make_tuple() 


Que- 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 


Answer- Returns the number of elements in a tuple 


Que- 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 


Answer- Swaps two tuples 


Que- What is the use of tie() function? 

a. Used to replace elements 

b. Used to delete elements 

c. Used to unpack the values of a tuple 

d. Used to check whether two tuples are the same or not 


Answer- Used to unpack the values of a tuple 


Que- How many variants of tie() function is there? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which word is used to stop the unpacking of a value in a tuple? 

a. stop 

b. ignore 

c. cancel 

d. remain 


Answer- ignore 


Que- 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 


Answer- Concatenates two tuples 


Que- Which header file is required to use complex class in your program? 

a. <complex> 

b. <math> 

c. <complex_math> 

d. <algorithm> 


Answer- <complex> 


Que- Which of the following is the correct syntax of declaring a complex number? 

a. complex variable_name<type>; 

b. complex<type> variable_name; 

c. Complex<type> variable_name; 

d. Complex variable_name<type>; 


Answer- complex<type> variable_name; 


Que- Which function is used to get the real part of the complex number? 

a. img_p() 

b. imag_p() 

c. real() 

d. real_p() 


Answer- real() 


Que- Which function is used to get the imaginary part of the complex number? 

a. real() 

b. imag() 

c. imag_p() 

d. real_p() 


Answer- imag() 


Que- Which function is used to get the argument of a complex number? 

a. abs() 

b. norm() 

c. arg() 

d. argu() 


Answer- arg() 


Que- What is the use of polar function? 

a. Used to construct a complex number from the real and imaginary part 

b. Used to construct a complex number from magnitude and phase angle 

c. Used to construct a complex number from the magnitude and real part 

d. Used to construct a complex number from argument and phase angle 


Answer- Used to construct a complex number from magnitude and phase angle 


Que- Which function is used to calculate the norm of a complex number? 

a. abs() 

b. norm() 

c. mod() 

d. square_sum() 


Answer- norm() 


Que- Which function is used to calculate the conjugate of a complex number? 

a. conj() 

b. reverse() 

c. opp() 

d. find_conj() 


Answer- conj() 


Que- What is the use of proj() function? 

a. Used to calculate the argument of a complex number 

b. Used to calculate the conjugate of a complex number 

c. Used to calculate the negative of a complex number 

d. Used to calculate the projection of a complex number 


Answer- Used to calculate the projection of a complex number 


Que- What is the use of log() function in a complex? 

a. To calculate the log of the imaginary part of a complex number 

b. To calculate the log of rethe al part of a complex number 

c. To calculate the log of a complex number 

d. To calculate the log of the argument of a complex number 


Answer- To calculate the log of a complex number 


Que- 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 


Answer- Container for efficient operations on an array 


Que- 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 


Answer- Supports element-wise mathematical operations 


Que- Which header file is required for using Valarray? 

a. <array> 

b. <Valarray> 

c. <stl> 

d. <algorithm> 


Answer- <Valarray> 


Que- 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 


Answer- Applies the manipulation provided to all the elements of the array 


Que- 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 


Answer- Returns the summation of all elements of Valarray 


Que- 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 


Answer- Returns new array after shifting elements by the given number 


Que- 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 


Answer- All of the mentioned 


Que- Which function is used to swap two Valarray? 

a. max() 

b. min() 

c. swap() 

d. change() 


Answer- swap() 


Que- Which function is used to print the maximum element from Valarray? 

a. change() 

b. min() 

c. swap() 

d. max() 


Answer- max() 


Que- What is bitset in C++? 

a. An array of bools consuming one bit per element 

b. Vector of bools 

c. C-like arrays of bool elements 

d. Template class 


Answer- An array of bools consuming one bit per element 


Que- Which of the following is correct about bitset and vector of bools? 

a. Space consumed by bitset is less than vector<bool> 

b. Bitset consume only 1 bit per element 

c. Number of elements in bitset should be known at compile time whereas vector can have a dynamic size 

d. All of the mentioned 


Answer- All of the mentioned 


Que- Which of the following is the limitation of bitset over vector bool? 

a. Space 

b. Size 

c. Type 

d. Speed 


Answer- Size 


Que- Which operator is used to access the nth bit in a bitset? 

a. -> 

b. [] 

c. . 

d. * 


Answer- [] 


Que- How many ways are there for constructing a bitset? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which is the correct syntax of constructing a bitset? 

a. bitset<size> b; 

b. bitset<size> b(12); 

c. bitset<size> b(string("1100")); 

d. all of the mentioned 


Answer- all of the mentioned 


Que- Which of the following is corect way of constructing bitset using integer number? 

a. bitset<size> b; 

b. bitset<size> b(12); 

c. bitset<size> b(string("1100")); 

d. bitset<size> b(float(12)); 


Answer- bitset<size> b(12); 


Que- Which of the following is corect way of constructing bitset using binary string? 

a. bitset<size> b; 

b. bitset<size> b(12); 

c. bitset<size> b(string("1100")); 

d. bitset<size> b(float(12)); 


Answer- bitset<size> b(string("1100")); 


Que- What is the default value of a bitset? 

a. All bits are 0 

b. All bits are 1 

c. Leftmost bit is 0 

d. Rightmost bit is 0 


Answer- All bits are 0 


Que- Which header file is required for using bitset in your program? 

a. <bit> 

b. <bitset> 

c. <bits> 

d. <BitSet> 


Answer- <bitset> 

Previous Post Next Post

Responsive Ad