Declarations, Arithmetic operators, Declarations -19 – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 31: Arithmetic operators -19

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

Programming Motion Control in C

1-19

Two limitations that apply to variable names are:

• Underscores (“_”) count as a letter, and should be used to enhance

readability.

• Upper and lower case letters are unique, so code and Code are two

distinct names.

It is very important to remember the last stipulation as you write
programs using variables. It is one of the most common sources of
program compilation problems.

Declarations

As mentioned in the section Variables, you must declare a variable by
its type before you can use that variable. You also may initialize the
variable at the time it is defined by following the variable name with
an equal sign and an expression to which the variable will be
initialized. For example:

int i = 0;

/* Initializes I to 0

(zero). */

rpm = velocity/line_count;

/* Calculates rpm from

velocity and line

count). */

Arithmetic Operators

The C programming language takes a slightly different tact with the
meaning of the = (equal sign) than arithmetic does. Rather than using
=

to mean equals in a mathematical sense, it is a value-assigning

operator. The statement

int i = 220;

initializes i to the value 220. You may find it easier to shift your
thinking when you encounter this statement from reading “i equals
220” to “assign the value 220 to the variable i.”

The arithmetic operators have assigned precedence and associate the
values on their left and right in a specific way. The table on page 1-20

Advertising