Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

operators computing direction

Tags:

People also ask

What are operators in computer?

1. In mathematics and sometimes in computer programming, an operator is a character that represents an action, as for example x is an arithmetic operator that represents multiplication. In computer programs, one of the most familiar sets of operators, the Boolean operators, is used to work with true/false values.

What are different types of operators?

There are three types of operator that programmers use: arithmetic operators. relational operators. logical operators.

What is the function of operators?

An operator is used to manipulate individual data items and return a result. These items are called operands or arguments. Operators are represented by special characters or by keywords.


I encountered something that I can't understand.

I have this code:

cout << "f1 * f1 + f2 * f1 - f1 / f2 is: "<< f1 * f1 + f2 * f1 - f1 / f2 << endl;

All the "f"s are objects, and all the operators are overloaded.

The weird this is that the first computation is of the / operator, then the second * and then the first *; after that, the operator + and at last, operator -.

So basically, the / and * worked from right to left, and the + and - operators worked from left to right.

I made another test... I checked this code:

 cout << "f1 * f1 / f2 is: " << f1 * f1 / f2 << endl;

Now, the first operator was * and only then operator /. So now, it worked from left to right.

Can someone help me understand why is there difference in the directions?

10X!


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!