Question
Question: Which of the following is an infix expression? A. \(\left( a+b \right)*\left( c+d \right)\) B. ...
Which of the following is an infix expression?
A. (a+b)∗(c+d)
B. ab+c∗
C. +ab
D. abc+∗
Solution
We first define the terms operator and operands. Depending on them, we find the infix and postfix expressions. We take examples to understand the concept better. In the given options, we find the operator which doesn't have all the operands.
Complete step by step answer:
The given condition of action between two given values is called the operator and two values which are bound by the operator are called the operands.Now for an operation if we have both operands on both sides of the operator then we call it an infix expression. The example being a+b. The operator is summation and we have both a and b to operate.
If we don’t have both operands on both sides of the operator then we call it a postfix expression. The example being a+. The operator is summation but we don’t have any value to operate with a. Now we take the given options. We can see that for operator ∗, in options ab+c∗, abc+∗, we don’t have any value.For operator +, in option +ab, we don’t have any value. Only in option A, (a+b)∗(c+d), we have all values for both operators ∗,+.Therefore, (a+b)∗(c+d) is an infix expression.
Hence, the correct option is A.
Note: Infix notation needs extra information to make the order of evaluation of the operators clear: rules built into the language about operator precedence and associativity, and brackets to allow users to override these rules. Operators are written after their operands.