 |
Chapter 1c - Variables |
|
Variables
Variables allow a program to store and retrieve volatile
data while the program is executing. Programs need variables
in order to be useful and range from single bits or floating
point numbers.
A variable must be declared before it can be used. Examples
of this are shown below;
bit onebitvariable;
/*
define a one bit variable named onebitvariable */
Since this is the first C statement shown, let's look at it
deeper. The bit
is a data declaration saying the variable named onebitvariable
can be used by the program. All variables must be declared
before being used so the program knows how to deal with it.
The semicolon ';' terminates the statement and the /*
starts a comment line and the */
terminates the comment line. The words within the /* and */
are just comments and produce no code. The color highlighting
is for illustrative purposes only and not needed in the code.
Here are the basic variables and how they are defined using
the Hi-Tech compiler. This are studied further in the basic
projects section.
The following type specifiers deal with 1 bit values.
|
bit |
Defines a 1-bit value |
The following type specifiers deal with 8 bit values.
|
unsigned char |
Defines an 8-bit unsigned value |
|
signed char |
Defines an 8-bit signed value |
|
char |
Defines an 8-bit signed value |
The following type specifiers deal with 16 bit values.
|
short |
Defines a 16-bit signed value |
|
int |
Defines a 16-bit signed value |
|
signed short |
Defines a 16-bit signed value |
|
signed int |
Defines a 16-bit signed value |
|
unsigned short |
Defines a 16-bit unsigned value |
|
unsigned int |
Defines a 16-bit unsigned value |
The floating point variable is not discussed in this guide
since it adds extra code which might exceed the limits of the
freeware C compiler.
|