C Programming - Expressions - Discussion
Discussion Forum : Expressions - General Questions (Q.No. 1)
1.
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
z = x + y * z / 4 % 2 - 1
Answer: Option
Explanation:
C uses left associativity for evaluating expressions to break a tie between two operators having same precedence.
Discussion:
92 comments Page 10 of 10.
Deepak Kumar said:
4 years ago
Hi @Sumath,
Since C uses left associativity for evaluating expressions to break a tie between two operators having the same precedence.
In given equation, z = x + y * z / 4 % 2 - 1.
* and / has same precedence so 1st divide it into two parts like z= x + y * z and z= z / 4 % 2 - 1. Then, apply the BODMAS rule in these two respectively.
You will get * first then + from the 1st equation.
Then,
/, % and -from 2nd equation.
Then,
Add = sign at the last.
So, finally, you will get;
*/%+-=
as per their precedence.
Hope this helps.
Since C uses left associativity for evaluating expressions to break a tie between two operators having the same precedence.
In given equation, z = x + y * z / 4 % 2 - 1.
* and / has same precedence so 1st divide it into two parts like z= x + y * z and z= z / 4 % 2 - 1. Then, apply the BODMAS rule in these two respectively.
You will get * first then + from the 1st equation.
Then,
/, % and -from 2nd equation.
Then,
Add = sign at the last.
So, finally, you will get;
*/%+-=
as per their precedence.
Hope this helps.
(5)
TEDD said:
2 months ago
BODMAS meaning.
B = BRACKETS
O = ORDERS/ EXPONENTIAL
D = DIVISION
M = MULTIPLICATION
A = ADDITIONS
S = SUBTRACTION
B = BRACKETS
O = ORDERS/ EXPONENTIAL
D = DIVISION
M = MULTIPLICATION
A = ADDITIONS
S = SUBTRACTION
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers