To Print Some Numbers


Load the file named oneint.c and display it on the monitor for our first example of how to
work with data in a C program.



main( )
{
int index;
index = 13;
printf("The value of the index is %d\n",index);
index = 27;
printf("The valve of the index = %d\n",index);
index = 10;
printf("The value of the index = %d\n",index);
}





The entry point "main" should be clear to you by now as well as the beginning brace. The first
new thing we encounter is the line containing "int index;", which is used to define an integer
variable named "index". The "int" is a reserved word in C, and can therefore not be used for
anything else. It defines a variable that can have a value from -32768 to 32767 on most MS-DOS
microcomputer implementations of C. It defines a variable with a value from -2147483648 to
2147483647 in HiTech C. Consult your compiler users manual for the exact definition for your
compiler. The variable name, "index", can be any name that follows the rules for an identifier and is not one of the reserved words for C. Consult your manual for an exact definition of an
identifier for your compiler. In HiTech C, the construction of identifier names is the same as
in UNIX, however 31 characters and both cases are significant. The compiler prepends an
underscore to external references in the assembler pass. The final character on the line, the
semi-colon, is the statement terminator used in C.
We will see in a later chapter that additional integers could also be defined on the same line,
but we will not complicate the present situation.
Observing the main body of the program, you will notice that there are three statements that
assign a value to the variable "index", but only one at a time. The first one assigns the value of
13 to "index", and its value is printed out. (We will see how shortly.) Later, the value 27 is
assigned to "index", and finally 10 is assigned to it, each value being printed out. It should be
intuitively clear that "index" is indeed a variable and can store many different values. Please
note that many times the words "printed out" are used to mean "displayed on the monitor". You
will find that in many cases experienced programmers take this liberty, probably due to the
"printf" function being used for monitor display.