Vidyalelo
C# Programming · Q13

Basic Syntax and Data Types in C Sharp

Programming · C# Programming · question 13

Q13

What is the output of the following code: Console.WriteLine(5 + 7 * 2);

A.
19
Answer
B.
24
C.
14
D.
17

Answer: Option A

Solution

Answer: Option A
Solution:
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.