Question
Download Solution PDFConsider following conditional statements if (m == 20 - 10 || n > 10). The order of execution of the following operations is
A. ==
B.-
C. ||
D. >
Choose the correct answer from the options given below:
Answer (Detailed Solution Below)
Option 3 : B, D, A, C
Detailed Solution
Download Solution PDFThe correct answer is Option 3.
Key Points
- To determine the order of execution of the operations in the given conditional statement
if (m == 20 - 10 || n > 10)
, we need to consider the operator precedence in C-like programming languages. - Operator precedence determines the order in which parts of an expression are evaluated.
- Here is the precedence of the operators involved, from highest to lowest:
- Subtraction (-)
- Relational equality (==)
- Relational greater than (>)
- Logical OR (||)
Additional Information
- According to the operator precedence:
- First, the subtraction operation (B) is performed:
20 - 10
. - Then, the equality operation (A) is evaluated:
m == 10
. - Next, the relational greater than operation (D) is evaluated:
n > 10
. - Finally, the logical OR operation (C) is performed to combine the two relational results.
- First, the subtraction operation (B) is performed:
- Thus, the order of execution is: B, D, A, C.
- Therefore, Option 3 is the correct answer.