• Home
  • Interview Questions
  • Online Quiz Tests
  • Blog
  • Contact Us

Global Guideline - Interviewer and Interviewee Guide

Links
  • Home
  • Interview Questions
  • Online Quiz Tests
  • Blog
  • Contact Us
  1. Interviews
  2. C++ Language
  3. C++ Operator Overloading

C++ Operator Overloading Question:

Output of this program?

#include <iostream>
using namespace std;
class myclass
{
public:
int i;
myclass *operator->()
{return this;}
};
int main()
{
myclass ob;
ob->i = 10;
cout << ob.i << " " << ob->i;
return 0;
}
a) 10 10
b) 11 11
c) error
d) runtime error

C++ Operator Overloading Interview Question
C++ Operator Overloading Interview Question

Answer:

a) 10 10


Previous QuestionNext Question
Output of this program?

#include <iostream>
using namespace std;
class Integer
{
int i;
public:
Integer(int ii) : i(ii) {}
const Integer
operator+(const Integer& rv) const
{
cout << "operator+" << endl;
return Integer(i + rv.i);
}
Integer&
operator+=(const Integer& rv)
{
cout << "operator+=" << endl;
i += rv.i;
return *this;
}
};
int main()
{
int i = 1, j = 2, k = 3;
k += i + j;
Integer ii(1), jj(2), kk(3);
kk += ii + jj;
}
a) operator+
operator+=
b) operator+=
operator+
c) operator+
operator+
d) None of the mentioned
The output of this program?

#include <iostream>
using namespace std;
ostream & operator<<(ostream & i, int n)
{
return i;
}
int main()
{
cout << 5 << endl;
cin.get();
return 0;
}
a) 5
b) 6
c) error
d) runtime error

Interview Categories:

    • Basic C++ Syntax
    • C++ Access Control
    • C++ COM ActiveX
    • C++ Constructors
    • C++ Containers
    • C++ Exception Handling
    • C++ Friend
    • C++ Inheritance
    • C++ Inline Function
    • C++ New And Delete
    • C++ Operator Overloading
    • C++ Pointers and Functions
    • C++ Programmer
    • C++ References
    • C++ Static Data
    • C++ Template
    • C++ Type Checking
    • C++ Virtual Functions

Most Popular Quiz Categories:

Java AWT And SwingHTMLSQLOOAD (Object Oriented Analysis and Design)SAT (Scholastic Aptitude Test) Sentence CorrectionBiology Aptitude TestStatistics Aptitude TestNetworkingChemistry Aptitude TestManagement

Most Popular Interviews

  • Business and Economy
  • Networking
  • Computer Programming
  • Operating System
  • Computer Hardware

Most Popular Quizzes

  • Information Technology
  • Networking
  • Engineering
  • Accounting
  • Java

Keep in touch with us

 

Copyright © 2007 - globalguideline.com

all rights reserved.
  • About Us
  • Contact Us
  • Blog
  • Terms of use
  • Privacy Policy