Vidyalelo
C++ Programming · Q15

Operators and Expressions in C++

Programming · C++ Programming · question 15

Q15

What is the result of the expression: 5 + 3 * 2 in C++?

A.
16
Answer
B.
11
C.
10
D.
Compiler error

Answer: Option A

Solution

Answer: Option A
Solution:
The correct answer is B: 11

Let's break down why:

C++ follows the standard order of operations (often remembered by the acronym PEMDAS/BODMAS).
This means:

* Parentheses/Brackets (None in this expression)
* Exponents/Orders (None in this expression)
* Multiplication and Division (from left to right)
* Addition and Subtraction (from left to right)

In the expression 5 + 3 * 2:

1. First, we perform the multiplication: 3 * 2 = 6
2. Then, we perform the addition: 5 + 6 = 11

Therefore, the result of the expression is 11.
Option A (16) is incorrect because it doesn't follow the order of operations (it would result from doing 5+3 first).
Option C (10) is incorrect for the same reason.
Option D (Compiler error) is incorrect. The expression is perfectly valid in C++ and will compile and run.