What is the output of the following code: Console.WriteLine(5 + 7 * 2);
A. 19
B. 24
C. 14
D. 17
Answer: Option A
Solution (By Examveda Team)
Understanding Operator Precedence:In C#, like in most programming languages, some operations are performed before others. This is called operator precedence.
Multiplication and Addition:
Multiplication (*) has higher precedence than addition (+). This means multiplication is done before addition.
Breaking Down the Code:
The expression
5 + 7 * 2
will be calculated as follows:1. First,
7 * 2
is evaluated, resulting in 14
.2. Then,
5 + 14
is evaluated, resulting in 19
.Therefore:
The
Console.WriteLine()
method will display the final result, which is 19.
The correct answer is A. 19