C Programming - Expressions

Exercise : Expressions - True / False Questions
1.
Associativity has no role to play unless the precedence of operator is same.
True
False
Answer: Option
Explanation:

Associativity is only needed when the operators in an expression have the same precedence. Usually + and - have the same precedence.

Consider the expression 7 - 4 + 2. The result could be either (7 - 4) + 2 = 5 or 7 - (4 + 2) = 1. The former result corresponds to the case when + and - are left-associative, the latter to when + and - are right-associative.

Usually the addition, subtraction, multiplication, and division operators are left-associative, while the exponentiation, assignment and conditional operators are right-associative. To prevent cases where operands would be associated with two operators, or no operator at all, operators with the same precedence must have the same associativity.


2.
The expression of the right hand side of || operators doesn't get evaluated if the left hand side determines the outcome.
True
False
Answer: Option
Explanation:
Because, if a is non-zero then b will not be evaluated in the expression (a || b)

3.
In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators
True
False
Answer: Option
Explanation:

The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b.


4.
Associativity of an operator is either Left to Right or Right to Left.
True
False
Answer: Option
Explanation:

Yes, the associativity of an operator is either Left to Right or Right to Left.