why to use operator overloading

Answers were Sorted based on User's Feedback



why to use operator overloading..

Answer / chandra

to achieve synchronization with the normal languages like c.
for example int a=10,b=30,c;
c = a+b ;
the above operation is possible in c as well as c++.bcos
the variables declared are primitive types.

If u want to do same thing for user defined datatypes, i
can say objects, we have to overload the operators.

For ex:
Assume that u created one class
Class A
and u have created objects
A obj1(10),obj2(30),obj3;

and u want the add 2 objects and result must be stored in
another object.

then u have to overload the operator + for class A.

obj3 = obj1 + obj2 ;

Is This Answer Correct ?    7 Yes 0 No

why to use operator overloading..

Answer / rekha

Operator overloading means giving additional meaning to
existing operators

Operators are defined to perform some operation on
fundamental types .Operator cannot work with user defined
types like classes and struct.so concept of operator
overloading means allows defining the meaning of operator so
that the can be used for performing operations on user defined
types.

Is This Answer Correct ?    3 Yes 0 No

why to use operator overloading..

Answer / r.ramakrishna

BY using the operator overloading we can the more than one
operator in single function.

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More OOPS Interview Questions

How to calculate the age from the date of birth by using the program?

2 Answers   Accenture,


What is the real time example of inheritance?

0 Answers  


Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 1 212 32123 4321234 543212345

7 Answers  


What is the fundamental idea of oop?

0 Answers  


Is following functions are said to be overloaded? int add(int a,int b) char *add(int a,int b)

4 Answers  


What do you mean by variable?

0 Answers  


What is stream in oop?

0 Answers  


Explain the advantages of inheritance.

0 Answers   TCS,


JAVA is FULLY OBJECT ORIENTED PROGRAMING LANGUAGE?

3 Answers  


What is Object and Class? What are the differences between them?

5 Answers  


Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3

3 Answers   Accenture, Cognizant, IBM,


write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.

4 Answers  


Categories