Solved

Difference between opeartor and function

Posted on 2004-04-25
5
183 Views
Last Modified: 2010-04-01
Hi,
does anybody have idea abt the difference in bettween opeartor and function in C/C++.

Thanks,
amit
0
Comment
Question by:agri_amit
[X]
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
5 Comments
 
LVL 5

Accepted Solution

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

i.e.

when you call   :
cin>>a;

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

0
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 25 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);




Cheers,
Stefan
0

Featured Post

Industry Leaders: 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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