• 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:

program Output:

#include <iostream>
using namespace std;
class sample
{
public:
sample(int i) : m_i(i) { }
public:
int operator()(int i = 0) const
{
return m_i + i;
}
operator int () const
{
return m_i;
}
private:
int m_i;
friend int g(const sample&);
};
int f(char c)
{
return c;
}
int main()
{
sample f(2);
cout << f(2);
return 0;
}
a) 3
b) 4
c) 5
d) None of the mentioned

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

Answer:

b) 4


Previous QuestionNext Question
What is the output of this program?

#include <iostream>
using namespace std;
class sample1
{
float i, j;
};
class sample2
{
int x, y;
public:
sample2 (int a, int b)
{
x = a;
y = b;
}
int result()
{
return x + y;
}
};
int main ()
{
sample1 d;
sample2 * padd;
padd = (sample2*) &d;
cout < result();
return 0;
}
a) 20
b) runtime error
c) random number
d) c or b
What is the output of this program?

#include <iostream>
#include <cmath>
using namespace std;
class Complex
{
private:
double real;
double imag;
public:
Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
{}
double mag()
{
return getMag();
}
operator double ()
{
return getMag();
}
private:
double getMag()
{
return sqrt(real * real + imag * imag);
}
};
int main()
{
Complex com(3.0, 4.0);
cout << com.mag();
cout << com;
return 0
}
a) 5 5
b) 4 5
c) 6 6
d) None of the mentioned

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