Chapter - 2: C Instructions

Fill the following table for the expressions given below and then evaluate the result.


C
Sections
1
Exercises

(a) g = 10/5/2/1;

Operator Left Right Remark
/ 10 5 or 5/2/1 The left operand is unambiguous, right is not
/ 5 or 10/5 2 or 2/1 Both left and right are ambiguous
/ 2 or 10/5/2 1 The right operand is unambiguous, the left is not

 

(b) b = 3/2 + 5*4 / 3

Operator left Right Remark
 / The left operand is unambiguous, right is not
+ 3/2 5*4 Both operands are unambiguous 
* 5 4 or 4/3 The left operand is unambiguous and right is not.
/ 4 or 5*4 3 The right operand is unambiguous and left is not

 

(c) a = b = c = 3 + 4;

Operator Left Right Remark
 = a  b or b = c = 3+4 Left operand is unambiguous but right is not 
= b or a = b c or c = 3 + 4 Both left abd right operand are unambiguous
= c or a = b = c 3 + 4 Right operand is unambiguous but left is not
+ 3 4 Both right and left operands are unambiguous

 

(d) x = 2 - 3 + 5 * 2 / 8 % 3;

Operator Left Right Remark
= x 2 - 3 + 5 * 2 / 8 % 3 Both operands are unambiguous
- + 3 or 3 + 5*2/8%3 The left operand is unambiguous but right is not
* 5 2 or 2/8%3 Left is unambiguous but right is not
/ 2 or 5*2 8 or 8%3 Both right and left operands are ambiguous
% 8 or 5*2/8 3 The right operand is unambiguous but left is not

 

(e) z = 5 % 3 / 8 * 3 + 4;

Operator Left Right Remark
 = 5 % 3 / 8 * 3  Both left and right operands are unambiguous 
% 5 3 / 8 * 3 Both left and right operand are unambiguous
/ 3 or 5%3 8 or 8*3 Both operands are ambiguous
* 8 or 5 % 3 / 8 3> Right operand is unambiguous but left is not
+ 5 % 3 / 8 * 3 4 Both operands are unambiguous

 

(f) y = z = -3 % -8 / 2 + 7;

Operator Left Right Remark
= z or y = z -3 % -8 / 2 + 7 Left is unambiguous but right is not
% -3 -8 or -8/2 Left is unambiguous but right is not
/ -8 or -3/-8 2 Right is unambiguous but left is not
+ -3 % -8 / 2 7 Both left and right are unambiguous

© 2020 Garbage Valuegarbage value logo