What is the output of this program?
1. #include2. using namespace std; 3. ostream & operator<<(ostream & i, int n) 4. { 5. return i; 6. } 7. int main() 8. { 9. cout << 5 << endl; 10. cin.get(); 11. return 0; 12. }
Operator overloading is
Which of the following statements is NOT valid about operator overloading?
What is the output of this program?
1. #include2. using namespace std; 3. class myclass 4. { 5. public: 6. int i; 7. myclass *operator->() 8. {return this;} 9. }; 10. int main() 11. { 12. myclass ob; 13. ob->i = 10; 14. cout << ob.i << " " << ob->i; 15. return 0; 16. }
1. #include2. using namespace std; 3. class Integer 4. { 5. int i; . public: 7. Integer(int ii) : i(ii) {} 8. const Integer 9. operator+(const Integer& rv) const 10. { 11. cout << "operator+" << endl; 12. return Integer(i + rv.i); 13. } 14. Integer& 15. operator+=(const Integer& rv) 16. { 17. cout << "operator+=" << endl; 18. i += rv.i; 19. return *this; 20. } 21. }; 22. int main() 23. { 24. int i = 1, j = 2, k = 3; 25. k += i + j; 26. Integer ii(1), jj(2), kk(3); 27. kk += ii + jj; 28. }
a) operator+
operator+=
b) operator+=
operator+
c) operator+
operator+
d) None of the mentioned