Difference between opeartor and function

Posted on 2004-04-25
Medium Priority
Last Modified: 2010-04-01
does anybody have idea abt the difference in bettween opeartor and function in C/C++.

Question by:agri_amit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

info_expert earned 75 total points
ID: 10915792
and operator behaves like function but a function does not behave like operator,


when you call   :

by default it is actually called:    >> as name of function and 'cin' and a are the parameters passsed.

LVL 12

Assisted Solution

stefan73 earned 75 total points
ID: 10916346
Hi agri_amit,
> the difference in bettween opeartor and function in C/C++
(I assume you mean C++ only, you can't redefine/overload operators in C)

From the compiler viewpoint, there's not much of a difference. Operators are just functions with a bit of syntactical sugar.

ostream & operator<<( ostream & o, A& a ) {
    o << a.my_int ;

This one you could call as
cout << my_instance;

or as
operator<<(cout, my_instance);


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question