| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

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

Total Questions: 20

1. In case of non-static member functions how many maximum object arguments a unary operator overloaded function can take?

Correct Answer is : x = x & (-x)

2. In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

Correct Answer is : octal, decimal, character, hexadecimal

3. In the case of friend operator overloaded functions how many maximum object arguments a unary operator overloaded function can take?

Correct Answer is : ANDing integer ‘a’ with ‘true’ :8

4. In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?

Correct Answer is : -1 1

5. What is the output of the following C++ code? #include #include using namespace std; class A { static int a;   public: void show() { a++; cout<<"a: "<
Correct Answer is : Compiler error may be possible

6. What is a binary operator?

Correct Answer is : STL component used to point a memory address of a container

7. Which is the correct example of a binary operator?

Correct Answer is : advance()

8. Which is the correct example of a unary operator?

Correct Answer is : 3

9. Which is called ternary operator?

Correct Answer is : Error

10. What is the output of the following C++ code? #include #include using namespace std; class complex {   int i; int j; public: complex(int a, int b) { i = a; j = b; }   complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; }   void show(){ cout<<"Complex Number: "<
Correct Answer is : 4

11. What is the output of the following C++ code? #include #include using namespace std; class complex { int i; int j; public: complex(){} complex(int a, int b) { i = a; j = b; }   complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; }   void show(){ cout<<"Complex Number: "<
Correct Answer is : 5

12. What is the output of the following C++ code? #include #include using namespace std; class complex { int i; int j; public: complex(){} complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; }   void operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; temp.show_poss(); }   void show(){ cout<<"Complex Number: "<
Correct Answer is : Input iterator moves sequentially forward

13. Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result? #include #include using namespace std; class Box { int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } };   int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"Box 2 has large capacity."; } else{ cout<<"Box 1 has large capacity."; } return 0; }

Correct Answer is : No value can be assigned to the location pointed by Input Iterator

14. Which is the correct statement about operator overloading?

Correct Answer is : All of the mentioned

15. Pick the incorrect statements out of the following.

Correct Answer is : Output Iterators are used for assigning

16. What is the output of the following C++ code? #include #include using namespace std; class Box { int capacity; Box(){} Box(double capacity){ this->capacity = capacity; }   };   int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); return 0; }

Correct Answer is : Output Iterator

17. What is the output of the following C++ code? #include #include using namespace std; class Box{ int capacity; bool operator<(Box b){ return this->capacity < b.capacity ? true : false; } public: Box(){} Box(double capacity){ this->capacity = capacity; }   };   int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"Box 2 has large capacity."; } else{ cout<<"Box 1 has large capacity."; } return 0; }

Correct Answer is : i only

18. Which operator should be overloaded in the following code to make the program error free? #include #include using namespace std; class Box{ int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } }; int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 == b2){ cout<<"Equal"; } else{ cout<<"Not Equal"; } return 0; }

Correct Answer is : Can be used as both accessing and assigning iterator

19. Give the function prototype of the operator function which we need to define in this program so that the program has no errors. #include #include using namespace std; class Box{ int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } };   int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 == b2){ cout<<"Equal"; } else{ cout<<"Not Equal"; } return 0; }

Correct Answer is : Forward Iterator that can be used in both directions

20. What is the output of the following C++ code? #include #include using namespace std; class Box{ int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } bool operator<(Box b){ return b.capacity < this->capacity? true : false; } };   int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"B1's capacity is small"; } else{ cout<<"B2's capacity is small"; } return 0; }

Correct Answer is : Iterators that can be used to access elements at an arbitrary offset position