Solved

Difference between opeartor and function

Posted on 2004-04-25
5
181 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

856 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