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

C++ Programming MCQ (Multiple Choice Questions)

 Que- How many categories of iterators are there in c++? 

a. 2 

b. 4 

c. 5 

d. 3 


Answer- 5 


Que- Which of the following can serve as random-access iterator? 

a. Memory pointer 

b. Object pointer 

c. Class pointer 

d. Memory & Class pointer 


Answer- Object pointer 


Que- What kind of pattern is iterator pattern? 

a. Design pattern 

b. Sequence pattern 

c. Adapter pattern 

d. Star pattern 


Answer- Design pattern 


Que- In which type of semantics does c++ implements iterator? 

a. Memory 

b. Size 

c. Pointer 

d. Value 


Answer- Pointer 


Que- By using which operator does point to next element is represent initerator? 

a. ++ 

b. -- 

c. +- 

d. -+- 


Answer- ++ 


Que- What is the use of checked iterators? 

a. Overwrite the bounds of your container 

b. Not allow you to overwrite the bounds of your container 

c. It will check the list value 

d. Overwrite the bounds of your iterators 


Answer- Not allow you to overwrite the bounds of your container 


Que- What will happen if the iterator is unchecked? 

a. Arising of compiler warnings 

b. Unchecked behavior on program 

c. Nothing will execute 

d. Arising of compiler warnings & Unchecked behavior on program 


Answer- Arising of compiler warnings & Unchecked behavior on program 


Que- How many adaptors support the checked iterators? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- What does the checked iterator allow you to find? 

a. Warnings 

b. Compile time error 

c. Run time error 

d. Warnings & Run time error 


Answer- Run time error 


Que- What kind of errors do checked iterators detect? 

a. Uninitialized iterators 

b. Initialized iterators 

c. Range access 

d. Both Uninitialized iterators and range access 


Answer- Both Uninitialized iterators and range access 


Que- Where are allocators used? 

a. Allocation of memory 

b. Deallocation of memory 

c. Used for pointers 

d. Both Allocation & Deallocation of memory 


Answer- Both Allocation & Deallocation of memory 


Que- Where are allocators implemented? 

a. Template library 

b. Standard library 

c. C++ code library 

d. String library 


Answer- Standard library 


Que- Which operator is used to allocate the memory? 

a. = 

b. + 

c. new 

d. free 


Answer- new 


Que- Which operator is used to deallocate the memory? 

a. destroy 

b. free 

c. empty 

d. insert 


Answer- free 


Que- Which header file is used to manipulate the allocater? 

a. allocater 

b. memory 

c. object 

d. iterator 


Answer- memory 


Que- What is the use of reference member type in allocator? 

a. Point to an element 

b. Quantities of element 

c. Reference to an element 

d. Sequence of an element 


Answer- Reference to an element 


Que- What is the correct syntax for declaring an allocator? 

a. template < class T > class allocator; 

b. template < class T > class; 

c. template class allocator; 

d. template class() 


Answer- template < class T > class allocator; 


Que- What are Iterators? 

a. STL component used to point a memory address of a container 

b. STL component used for vectors 

c. STL component used to call functions efficiently 

d. STL component used to define template classes 


Answer- STL component used to point a memory address of a container 


Que- Which function is used increment the iterator by a particular value? 

a. next() 

b. advance() 

c. prev() 

d. move() 


Answer- advance() 


Que- How many types of Iterators are there? 

a. 5 

b. 2 

c. 3 

d. 4 


Answer- 5 


Que- Pick the correct statement. 

a. Input iterator moves sequentially forward 

b. Input iterator moves sequentially backward 

c. Input iterator moves in both direction 

d. Input iterator moves sequentially downwards 


Answer- Input iterator moves sequentially forward 


Que- Which of the following is correct about Input Iterators? 

a. Input iterators can be used with all relational operators 

b. Input iterators can work with arithmetic operators 

c. No value can be assigned to the location pointed by Input Iterator 

d. Input iterators can work with sequence operators 


Answer- No value can be assigned to the location pointed by Input Iterator 


Que- Which of the following is correct about Input Iterators? 

a. They cannot be decremented 

b. Cannot be used in multi-pass algorithms 

c. Can only be incremented 

d. All of the mentioned 


Answer- All of the mentioned 


Que- Which of the following is correct? 

a. Input Iterators are used for assigning 

b. Output Iterators are used for assigning 

c. Both Input and Output Iterators are used for accessing 

d. Both Input and Output Iterators are used for assigning 


Answer- Output Iterators are used for assigning 


Que- Which of the following is an advantage of Forward iterator over input and output iterator? 

a. Can be used as both accessing and assigning iterator 

b. Forward iterator can be incremented or decremented 

c. Can be used with relational operators also 

d. Can be used with arithmetic operators also 


Answer- Can be used as both accessing and assigning iterator 


Que- What are Bi-directional iterators? 

a. Iterator same as Forward Iterator 

b. Forward Iterator that can be used in both directions 

c. Iterator that can only be used to access the sequence from both sides 

d. Iterator that can only be used to assign the sequence from both sides 


Answer- Forward Iterator that can be used in both directions 


Que- What are Random-access Iterators? 

a. Iterators that can be used to access elements at an arbitrary offset position 

b. Same as Bi-directional iterator 

c. Input iterator with the additional property of random access 

d. Output iterator with the additional property of random access 


Answer- Iterators that can be used to access elements at an arbitrary offset position 


Que- Which of the header file is used to implement algorithms provided by C++ STL? 

a. <algorithm> 

b. <header> 

c. <algos> 

d. <Algorithm> 


Answer- <algorithm> 


Que- How many types of sequence operations are provided by the C++ algorithm STL? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which of the following is a Modifying Sequence Operation? 

a. all_of() 

b. any_of() 

c. equal() 

d. swap() 


Answer- swap() 


Que- Which of the following is a Non-modifying Sequence Operation? 

a. swap() 

b. transform() 

c. remove() 

d. search() 


Answer- search() 


Que- What is the use of random_shuffle() function of STL algorithm? 

a. To generate the random sequence in a range 

b. To generate a sequence in a given range and arrange them in random order 

c. To rearrange given sequence randomly 

d. To select any random number from the given sequence. 


Answer- To rearrange given sequence randomly 


Que- What is the property of stable sort function provided by the STL algorithm? 

a. sorts the elements of a sequence in ascending order preserving the relative order of equivalent elements 

b. sorts the elements of a sequence in descending order preserving the relative order of equivalent elements 

c. arranges the sequence randomly preserving the relative order of equivalent elements 

d. same as sort function of STL algorithm 


Answer- sorts the elements of a sequence in ascending order preserving the relative order of equivalent elements 


Que- What is the property of partial sort function provided by the STL algorithm? 

a. sorts the elements before the middle element in ascending order and remaining elements are left without any specific order 

b. sorts the elements before the middle element in descending order and remaining elements are left without any specific order 

c. sorts the elements after the middle element in ascending order and remaining elements are left without any specific order 

d. sorts the elements after the middle element in descending order and remaining elements are left without any specific order 


Answer- sorts the elements before the middle element in ascending order and remaining elements are left without any specific order 


Que- Which function can be used to find the sum of a vector container? 

a. findsum() 

b. accumulate() 

c. calcsum() 

d. checksum() 


Answer- accumulate() 


Que- Which header file is required to use accumulate() function? 

a. <algorithm> 

b. <numeric> 

c. <vector> 

d. <iostream> 


Answer- <numeric> 


Que- What are functors in C++? 

a. Objects of a class which are treated as functions 

b. Objects that are used to call the function of other classes 

c. Functions that are called using pointer objects 

d. Functions that are called only once in a program 


Answer- Objects of a class which are treated as functions 


Que- Which of the following operators are overloaded for functors? 

a. [] 

b. () 

c. << 

d. >> 


Answer- () 


Que- What is the correct function prototype of () operator overloading? 

a. return_type operator(arguments)(); 

b. return_type operator(arguments); 

c. return_type operator()(arguments); 

d. return_type operator(Class_name)(arguments); 


Answer- return_type operator()(arguments); 


Que- Which of the following is correct about Functors? 

a. Functors should not be declared outside the main function 

b. Overloaded operator () function is not a member of the class 

c. Functors should be declared global 

d. Functors have a state 


Answer- Functors have a state 


Que- Which of te following is a built-in example of functors in C++? 

a. mltiplication<T> f(a1, a2); 

b. add<T> f(a1, a2); 

c. subtract<T> f(a1, a2); 

d. plus<T> f(a1, a2); 


Answer- plus<T> f(a1, a2); 


Que- Which of the following header file is required to use in-bulit functors of C++? 

a. <any> 

b. <fucntional> 

c. <functor> 

d. <function> 


Answer- <fucntional> 


Que- What are unary functors? 

a. Functors that accepts only one parameter 

b. Functors that accepts two parameters 

c. Functors that accepts more than one parameters 

d. Functors that accepts other than a specific type of parameter 


Answer- Functors that accepts only one parameter 


Que- What are binary functors? 

a. Functors that accepts only one parameter 

b. Functors that accepts more than one parameters 

c. Functors that accepts two parameters 

d. Functors that accepts other than a specific type of parameter 


Answer- Functors that accepts two parameters 


Que- How many ways are there to use functors? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which of the following is a logical unary functor? 

a. logical_or<T> f; 

b. logical_and<T> f; 

c. logical_not<T> f; 

d. negate<T> f; 


Answer- logical_not<T> f; 


Que- What of the following is the equivalent statement for the functor call, x = f(arg1, arg2); where f is a functor and arg1 and arg2 are the arguments required by the functors? 

a. f.call(arg1, arg2); 

b. f.operator()(arg1, arg2); 

c. f.operator(arg1, arg2); 

d. f.operator(arg1, arg2)(); 


Answer- f.operator()(arg1, arg2); 


Que- Which is an instantiation of the basic_string class template? 

a. Character 

b. String class 

c. Memory 

d. Iterator 


Answer- String class 


Que- Which character is used to terminate the string? 

a. $ 

b. Null 

c. Empty 

d. @ 


Answer- Null 


Que- How does the strings are stored in the memory? 

a. Contiguous 

b. Non-contiguous 

c. Null 

d. sequence 


Answer- Contiguous 


Que- Where are the strings stored? 

a. Stack 

b. Heap 

c. Both Stack & Heap 

d. Queue 


Answer- Both Stack & Heap 


Que- What will happen if a string is empty? 

a. It can't be created 

b. Raises an error 

c. It can be used 

d. It cannot be used 


Answer- It can be used 


Que- Which header file is used to manipulate the string? 

a. iostream 

b. iomanip 

c. string 

d. container 


Answer- string 


Que- How many maximum number of parameters does a string constructor can take? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which constant member functions does not modify the string? 

a. bool empty() 

b. assign 

c. append 

d. delete 


Answer- bool empty() 


Que- What is the difference between unsigned int length() and unsigned int size()? 

a. Returns a different value 

b. They are same 

c. Returns a different value but they are same 

d. Returns a length 


Answer- They are same 


Que- How many parameters can a resize method take? 

a. 1 

b. 2 

c. 1 or 2 

d. 2 


Answer- 1 or 2 


Que- Where are standard C libraries defined in C++? 

a. Container 

b. std namespace 

c. list 

d. iterators 


Answer- std namespace 


Que- Which of the following have their changes in their declaration related to constness of parameter? 

a. strchr 

b. string 

c. memory 

d. strcybrk 


Answer- strchr 


Que- How many elements does a floating point number is composed of? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 4 


Que- How does the limits.h header file can be represented in C++? 

a. limits 

b. limit 

c. climits 

d. dlimits 


Answer- climits 


Que- Pick out the correct syntax of the header file that can be used with C++. 

a. #include <float> 

b. #include <float.h> 

c. Both #include <float> & #include <float.h> 

d. #include <flot.h> 


Answer- #include <float.h> 


Que- How many groups of output of operation are there in c++? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Pick out the correct objects about the instantiation of output stream. 

a. cout 

b. cerr 

c. clog 

d. all of the mentioned 


Answer- all of the mentioned 


Que- What is meant by ofstream in c++? 

a. Writes to a file 

b. Reads from a file 

c. Writes to a file & Reads from a file 

d. delete a file 


Answer- Writes to a file 


Que- How many types of output stream classes are there in c++? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- What must be specified when we construct an object of class ostream? 

a. stream 

b. streambuf 

c. memory 

d. steamostream 


Answer- streambuf 


Que- Which operator is used for input stream? 

a. > 

b. >> 

c. < 

d. << 


Answer- >> 


Que- Where does a cin stops it extraction of data? 

a. By seeing a blank space 

b. By seeing ( 

c. By seeing a blank space & ( 

d. By seeing < 


Answer- By seeing a blank space 


Que- Which is used to get the input during runtime? 

a. cout 

b. cin 

c. coi 

d. cinout 


Answer- cin 


Que- How many parameters are there in getline function? 

a. 1 

b. 2 

c. 2 or 3 

d. 3 


Answer- 2 or 3 


Que- What can be used to input a string with blank space? 

a. inline 

b. getline 

c. putline 

d. setline 


Answer- getline 

Previous Post Next Post