Operator Precidence

Let us examine hands-on how FORTRAN is able to evaluate an expression. Because all of the arithmetic operators available to us (+,-,*,/,**) have built-in priority precedences, the compiler is able to make sense of a complicated expression in a program, even if it contains no parenthetical documentation. (Use of parentheses in your expressions can be a helpful way to aid readability and ensure that your expression is evaluated in the way that you have intended).

Choose the area below to see either a demonstration of how to solve a difficult arithmetic problem in FORTRAN, or an example that can solve yourself.



DEMO

Precidence Rules

parenthesis
()
left to right

exponents
**
right to left

multiply/divide
* or /
left to right

add/subtract
+ or -
left to right


Logical operations
not included.


EXAMPLE

Below is provided an example that will allow you to use your mouse to evaluate the parts of an arithmetic expression in the proper order. A message will appear at each click near the bottom of the page explaining the current state. You will not be allowed to progress past the point of a mistake in the selection of the next operator to evaluate.

The expression found below contains variables A, B, and C, where A and C are of type INTEGER and B is of type REAL. Assume that A = 150, B = 4.0, and C = 3. The variable ANSWER is used to store the result of the expression and is of type REAL.



Created by Dave Doyle, ddoyle@davedoyle.com and Brent Dahlen, dahlen@cs.umn.edu, 1996.