what is the priority order of mathematical operators in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the priority order of mathematical operators in C++?

18th Jun 2016, 12:17 PM
Sakshi Jain
Sakshi Jain - avatar
2 Answers
+ 2
in most cases it's just left to write. so if we type 3 / 4 * 5, we'll get 0 (assuming we're using ints) 5 * 4 / 3, we'll get 6. primarily the rule of thumb I follow is no more than 3 calculations in one line. however if we use parentheses those calculations are done before others interact with it. so let's say we have 3 / 4 * 5, and we want to make sure we always get 4 * 5 first, we should instead write 3 / (4*5), same as on math
18th Jun 2016, 12:37 PM
destro
+ 2
The operator precedence of C++ is the standard mathematical precedence, where % has the same precedence as /.
2nd Mar 2017, 6:25 PM
Rohit Ranjan
Rohit Ranjan - avatar