C++ interview questions part 52

C++ interview questions part 52

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What is the output of the following C++ program? #include #include   using namespace std;   int main () { pair p(1,2); cout<<"Pair(first,second) = ("<
Correct Answer is : 10


2. What is the output of the following C++ code?
#include   
#include 
 
using namespace std;
 
int main () 
{
  pair p;
  p = make_pair(1,2);
  cout<<"Pair(first,second) = ("<
                                        
Correct Answer is : func1


3. Which of the following is correct way of copying the values of pair p1 into other pair p2?

Correct Answer is : Both 1 & 2

4. What happens if a pair is not initialized?

Correct Answer is : I have 4 apples

5. Which of the following Operator cannot be used with pairs?

Correct Answer is : Executed

6. What is the output of the following C++ code? #include #include #include   using namespace std;   int main () { pair p1(1,2); pair p2(3,4); cout<<"Pair(first,second) = ("<
Correct Answer is : Interface


7. What is the output of the following C++ code? #include #include #include   using namespace std;   int main () { pair p1(1,2); pair p2(3,4); if(p1 <= p2) cout<<"P1 is small"; else cout<<"P2 is small"; return 0; }

Correct Answer is : It combines the first operand and the second operand

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

Correct Answer is : both random and cstdlib

9. What is the output of the following C++ code? #include #include #include   using namespace std;   int main() { vector v(10, 2); if (all_of(v.cbegin(), v.cend(), [](int i){ return i % 2 == 0; })) { cout << "All numbers are even\n"; } else { cout << "All numbers are not even\n"; } return 0; }

Correct Answer is : RAND_MAX

10. How many types of sequence operations are provided by the C++ algorithm STL?

Correct Answer is : 1

11. Which of the following is a Modifying Sequence Operation?

Correct Answer is : 0​ to RAND_MAX

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

Correct Answer is : Depends on the compiler

13. What is the use of random_shuffle() function of STL algorithm?

Correct Answer is : Any number from 0 to 99

14. What is the output of the following C++ code? #include #include #include   using namespace std;   int main() { vector v; for(int i=0;i<10;i++) v.push_back(i+1); for(int i=0;i<10;i++) cout<
Correct Answer is : Any two number from 1 to 10


15. What is the output of the following C++ code? #include #include #include   using namespace std;   bool IsOdd (int i) { return (i%2)==1; }   int main () { vector v;   for (int i=1; i<=10; ++i) v.push_back(i);   vector::iterator bound; bound = partition (v.begin(), v.end(), IsOdd);   for (vector::iterator it=v.begin(); it!=bound; ++it) cout << ' ' << *it; cout << '\n';   for (vector::iterator it=bound; it!=v.end(); ++it) cout << ' ' << *it; cout << '\n';   return 0; }

Correct Answer is : 1

16. What is the output of the following C++ code? #include #include #include   using namespace std;   bool IsOdd (int i) { return (i%2)==1; }   int main () { vector v = {4,2,10,5,1,8}; for(int i=0;i
Correct Answer is : both % and modulo operator


17. What is the property of stable sort function provided by the STL algorithm?

Correct Answer is : Time

18. What is the property of partial sort function provided by the STL algorithm?

Correct Answer is :

19. What is the output of the following C++ code? #include #include #include   using namespace std;   int main () { vector v = {4,2,10,5,1,8}; sort(v.begin(), v.end()); if (binary_search(v.begin(), v.end(), 4)) cout << "found.\n"; else cout << "not found.\n"; return 0; }

Correct Answer is : A reference value once defined can be reassigned

20. What is the output of the following C++ code? #include #include #include   using namespace std;   int main () { vector v = {4,2,10,5,1,8}; if (binary_search(v.begin(), v.end(), 4)) cout << "found.\n"; else cout << "not found.\n"; return 0; }

Correct Answer is : &

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon