57.5k views
1 vote
True or False? In C++, the expression (a + b / c) / 2 is implicitly parenthesized as ((a + b) / c) / 2.

User SJU
by
5.6k points

1 Answer

4 votes

Answer:

False

Step-by-step explanation:

The two statements are NOT equivalent since the first statement follows the rule of operator precedence in C++ which assigns highest precendence to values in parenthesis, then division, multiplication, additions and subtraction in that order. In other verify their difference consider this code snippet

int a =2;

int b =3;

int c =5;

cout( (a + b / c) / 2); // outputs 1

cout(((a + b) / c) / 2); // outputs 0 because a+b is evaluated first

User Brandon Yang
by
5.7k points