Solved

Difference between opeartor and function

Posted on 2004-04-25
5
182 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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