You are on page 1of 8

Memory Concepts

Variable names, such as number1, number2 and


sumOfNumbers, correspond to actual locations in the
computer's memory.

Every variable has a name, type, size and value.

Arithmetic

The majority of arithmetic operators are binary operators,


because each operates using two operands.
There is a separate operators for integer division (the
backslash, \) and floatingpoint division (the forward
slash, /).
Integer division takes two Integer operands and yields an
Integer result; for example, the expression 7\4 evaluates to
1, and the expression 17 \ 5 evaluates to 3.
Any fractional part in the Integer division result simply is
discarded (i.e., truncated)—no rounding occurs.
When floating-point numbers are used with the integer
division operator, the numbers are first rounded to the
nearest whole number, then divided.
7.1 \ 4 evaluates to 1

7.7 \ 4 evaluates to 2
The modulus operator, Mod, yields the remainder after
Integer division.
7 Mod 4 yields 3
17 Mod 5 yields 2
Arithmetic expressions in must be written in straight-line
form so that programs can be entered into a computer.

Expressions such as “a divided by b” must be written as a/b


so that all constants (such as 45 and 72 in the previous
example), variables and operators appear in a straight line.
not acceptable to compilers:
a
b
Programing language applies the operators in arithmetic
expressions in a precise sequence, determined by the
following rules of operator precedence, which are generally
the same as those followed in algebra:

1. Operators in expressions contained within a pair of


parentheses are evaluated first. With nested (or
embedded) parentheses, the operators contained in the
innermost pair of parentheses are applied first.
2. Exponentiation is applied next. If an expression contains
several exponentiation operations, operators are applied
from left to right

3. Unary positive and negative, + and -, are applied next. If


an expression contains several sign operations, operators
are applied from left to right. Sign operations + and - are
said to have the same level of precedence
4. Multiplication and floating-point division operations are
applied next. If an expression contains several
multiplication and floating-point division operations,
operators are applied from left to right. Multiplication and
floating-point division have the same level of precedence.

5. Integer division is applied next. If an expression contains


several Integer division operations, operators are applied
from left to right.
6. Modulus operations are applied next. If an expression
contains several modulus operations, operators are applied
from left to right

7. Addition and subtraction operations are applied last. If


an expression contains several addition and subtraction
operations, operators are applied from left to right.
Addition and subtraction have the same level of
precedence.

You might also like