An arithmetic expression is an expression using additions +, subtractions -, multiplications *, divisions /, and exponentials **

An arithmetic expression is an expression that results in a numeric value.

Types of numeric values

  1. Integers (whole numbers), and 
  2. Real or floating point numbers (numbers containing a decimal point). 

An arithmetic expression is a syntactically correct combination of numbers, operators, parenthesis, and variables.

Examples:

  • 1 + 3 is 4
  • 1.23 - 0.45 is 0.78
  • 3 * 8 is 24
  • 6.5/1.25 is 5.2
  • 8.4/4.2 is 2.0 rather than 2, since the result must be of Real type.
  • -5**2 is -25
  • 12/4 is 3
  • 13/4 is 3 rather than 3.25. Since 13/4 is a single mode arithmetic expression and since all of its operands are of INTEGER type, the result must also be of INTEGER type. The computer will truncate the mathematical result (3.25) making it an integer. Therefore, the result is 3.
  • 3/5 is 0 rather than 0.6.

Operator Priority:

Operator

Meaning

Priority

() Parenthetical groups 0

^

power 1

-

negation 2

/

devide 3

*

multiply 3

+

addition 4

-

subtraction 4

 

If operators have same priority do them left to right.

Infix, Prefix and Postfix Expressions:

Examples:

Infix Expression
Prefix Expression
Postfix Expression
A + B + A B A B +
A + B * C + A * B C A B C * +
(A + B) * C * + A B C A B + C *
A + B * C + D + + A * B C D A B C * + D +
(A + B) * (C + D) * + A B + C D A B + C D + *
A * B + C * D + * A B * C D A B * C D * +
A + B + C + D + + + A B C D A B + C + D +