0
Why the output of this code is 2 ?????
Predict the output of following using operator precedence:- 5-2*3+3
4 Answers
+ 8
Do you remember learning about PEMDAS in school? It applies similarly to programs, but not exactly.
Parentheses are done first, multiplication AND division are done left-to-right, and addition AND subtraction are done left-to-right.
So in this example, you'd do 2 * 3 first, then 5 - 6, then -1 + 3.
+ 1
Apply BODMAS rule and precedence of operators in C language... *,/ are of same precedence and +,- are of same precedence ...(*,/) > (+,-)...and in tie cases, it follows left to right approach. As we have only one higher precedence operator i.e., *... 2*3=6 will be performed first...5-6=-1 performed second and lastly -1+3=2 ...hence the answer:2
+ 1
multiplication gets 1st priority
so, -2*3=-6
then addition
so -6+3=-3
then subtraction
so 5-3=2 .
0
yeah! i got it thanks all..