250+ TOP MCQs on Modifying Sequence Algorithms and Answers

This section on C++ language interview questions and answers on “Modifying Sequence Algorithms”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ language interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ language interview questions on “Modifying Sequence Algorithms” along with answers, explanations and/or solutions:

1. What is the use of middle parameter in the rotate method?
a) Marks the begining of a sequence
b) Marks the ending of a sequence
c) Marks the elements in a sequence
d) Marks the digits in a sequence
Answer: c
Clarification: Forward iterator pointing to the element within the range and that can be moved to the first position in the range.

2. What kind of object is modifying sequence algorithm?
a) Function template
b) Class template
c) Method
d) Iterator
Answer: a
Clarification: It is a group of functions and implemented under algorithm header file.

3. How the sequence of objects can be accessed?
a) Iterators
b) Pointers
c) Both Iterators & Pointers
d) Library
Answer: c
Clarification: A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.

  250+ TOP MCQs on Buffering and Answers

4. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         vector<int> myvector (5);
  8.         fill (myvector.begin(), myvector.begin() + 4, 5);
  9.         fill (myvector.begin() + 3,myvector.end() - 2, 8);
  10.         for (vector<int> :: iterator it = myvector.begin();
  11.             it != myvector.end(); ++it)
  12.         cout << ' ' << *it;
  13.         return 0;
  14.     }

a) 5 5 5 5 0
b) 8 8 8 8 0
c) 5 8 5 8 0
d) 5 5 5 5 5
Answer: a
Clarification: In this program, We filled up all the vector values by using fill method.
Output:

$ g++ msa.cpp
$ a.out
5 5 5 5 0

5. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main ()
  6.     {
  7.         int myints[]={ 10, 20, 30, 40, 50 };
  8.         vector<int> myvector (4, 99);
  9.         iter_swap(myints, myvector.begin());
  10.         iter_swap(myints + 3,myvector.begin() + 2);
  11.         for (vector<int> :: iterator it = myvector.begin(); 
  12.             it != myvector.end(); ++it)
  13.         cout << ' ' << *it;
  14.         return 0;
  15.     }

a) 10
b) 10 40
c) 10 99 40 99
d) 99 40 10
Answer: c
Clarification: In this program, We are swapping the certain values in two vectors by using iter_swap.
Output:

$ g++ msa1.cpp
$ a.out
10 99 40 99

6. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     #include 
  5.     using namespace std;
  6.     int op_increase (int i)
  7.     {
  8.         return ++i;
  9.     }
  10.     int main ()
  11.     {
  12.         vector<int> a;
  13.         vector<int> b;
  14.         for (int i = 1; i < 4; i++)
  15.         a.push_back (i * 10);
  16.         b.resize(a.size());
  17.         transform (a.begin(), a.end(), b.begin(), op_increase);
  18.         transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
  19.         for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
  20.             cout << ' ' << *it;
  21.         return 0;
  22.     }

a) 21
b) 41
c) 61
d) 21 41 61
Answer: d
Clarification: In this program, We allocated the values to the vector and then by using transform function, We increased the values.
Output:

$ g++ msa2.cpp
$ a.out
21 41 61

7. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 };
  7.         int* pbegin = myints;
  8.         int* pend = myints + sizeof(myints) / sizeof(int);
  9.         pend = remove (pbegin, pend, 20);
  10.         for (int* p = pbegin; p != pend; ++p)
  11.             cout << ' ' << *p;
  12.         return 0;
  13.     }

a) 10 20 30
b) 10 30 30 10 10
c) 10 20 30 30
d) 40 20 10 20
Answer: b
Clarification: In this program, We removed the values in the vector by using the remove method.
Output:

$ g++ msa3.cpp
$ a.out
10 30 30 10 10

8. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         int myints[] = { 10, 20, 30 ,40 };
  8.         int * p;
  9.         p = find (myints, myints + 4, 30);
  10.         --p;
  11.         cout << *p << 'n';
  12.         return 0;
  13.     }

a) 10
b) 20
c) 30
d) 40
Answer: b
Clarification: In this program, We used the find method to find the value before 20.
Output:

$ g++ msa4.cpp
$ a.out
20

9. How many kind of operation can be applied to transform method in c++?
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: There are two kinds of operations. They are unary and binary operation.

10. What operator is used to remove the dupplicates in the range?
a) )
b) ^
c) %
d) ==
Answer: d
Clarification: The function uses operator== to compare the pairs of elements.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top