14-03-2012, 03:08 PM
A Quick Introduction to C Programming
[attachment=18329]
Writing and Running Programs
1. Write text of program (source code) using an editor such as emacs, save as file e.g. my_program.c
2. Run the compiler to convert program from source to an “executable” or “binary”:
$ gcc –Wall –g my_program.c –o my_program
3-N. Compiler gives errors and warnings; edit source file, fix it, and re-compile
A Quick Digression About the Compiler
In Preprocessing, source code is “expanded” into a larger form that is simpler for the compiler to understand. Any line that starts with ‘#’ is a line that is interpreted by the Preprocessor.
Include files are “pasted in” (#include)
Macros are “expanded” (#define)
Comments are stripped out ( /* */ , // )
Continued lines are joined ( \ )
The number of a slot is its Address.
One byte Value can be stored in each slot
What is “Memory”?
A Type names a logical meaning to a span of memory. Some simple types are:
a single character (1 slot)
an array of 10 characters
signed 4 byte integer
4 byte floating point
signed 8 byte integer