Skip to content Skip to sidebar Skip to footer

Program Of Power Operator In C

I'm creating a library which will have concepts similar kind of python. C doesn't have any power operator like python has (**) (e.g. pow(x,n) is equivalent to x**n in python). I tr

Solution 1:

You cannot add new operators to C++, so using ** (or some other new thing) is out. Also, you cannot overload operators when both sides are built-in types, therefore using an existing operator (e.g. ^) to implement raising floats/ints to powers that are floats/ints is also out. See this question on Stroustrup's C++ FAQ (as mentioned in the comments below.)

You can implement you own numeric class and overload any operator you want for it, but it won't be easy and it won't be as "elegant" or as cool as you seem to think.

So, just use a function.

Post a Comment for "Program Of Power Operator In C"