Introduction to Algorithms and Programming
Reading source code
Reading source code to learn programming
The habit of reading source code helps programmers to:
- Learn problem solving techniques
- Recognize good software development practices
- Recognize the negative consequences of bad software development practices
- Learn programming techniques
In professional environments, reading source code is often required to:
- Improve existing software
- Fix errors in existing software
- Re-use techniques and existing software
- Inspect software during the testing phase
C is a procedural language
The
main() function is
required for all C programs.
- The main() function is the where the program starts.
- The program ends when the main() function ends.
- The main() function should be defined before all other functions.
Preprocessor directives
The
preprocessor directive is used to include the source code from the
stdio.h header file into the current program.
- Header files have names ending with a .h extension.
- Header files used with a program should be included at the top of the source code file for easier maintenance.
Statements
C programs use 2 types of
statements.
- Simple statements end with a semicolons.
- Compound or complex statements are enclosed in curly braces. They contain one or more simple statements.
Function calls and input parameters
Function calls require a pair of
parentheses after the name of the function.
- Optionally, input parameters are provided by including it within the parentheses.
- A comma is required to separate multiple input parameters.
Source code comments
Comments start with
/* and continue until it reaches a matching
*/ end.
Do not use C++, Java or PHP style comments, which use a
double forward slash at the start of comments.
// Do NOT use comments in this style
// They reduce portability between C compilers
When reading the source code, pay attention to the usage of curly braces, parentheses and semicolons in the programs.
Steps to create C programs

Reserved keywords in the C language
Reserved keywords may
not be used as names of functions or data variables.
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
const | float | short | unsigned |
continue | for | signed | void |
default | goto | sizeof | volatile |
do | if | static | while |