ExamVeda
Login
Home
Basic Syntax and Data Types in C Sharp
?

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

Answer & Solution
Correct Answer: Option A
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Minh Đạt
Minh Đạt 2 years ago
The correct answer is A. 19