+ 5

In c the operators *,/,% which has the higher priority?

please tell 2*6/4%2=?

15th Mar 2018, 5:09 PM
Saranya
Saranya - avatar
4 Answers
+ 10
* , / , % have same precedence ... so associativity plays all game in this case , associativity is from left to right , which means that if these are present together ... then the operator which comes first from the left will get executed first ... ie first * then / & the % in above case //hope it helps best to understand precedence & associativity for these operators
15th Mar 2018, 5:36 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 6
for more information as my friends said above check that: http://en.cppreference.com/w/c/language/operator_precedence
15th Mar 2018, 5:52 PM
Baraa AB
Baraa AB - avatar
+ 4
For what I know they have the same precedence. but in situations like the expression: 2 * 6 / 4 % 2 They are evaluated from left to right. So a step by step evaluation would do: step 1. (2 * 6) / 4 % 2 = 12 / 4 % 2 step 2. (12 / 4) % 2 = 3 % 2 step 3. 3 % 2 = 1 EDITED: and here is the code to prove: https://code.sololearn.com/cu7Db4WPkzne/?ref=app
15th Mar 2018, 5:23 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
en matematicas existe un orden operacional, en el que cuando no estan las parentesis, se sigue ese orden , ese orden es el mismo que sigue el orden aritmetico de los operadores , estudialo para que no sea tan confuso
19th Nov 2020, 12:13 AM
bob
bob - avatar