Introduction to C
Chapter 1
Objectives of this chapter:
-
Introduction
-
History and Background of the C Programming Language
-
Virtues of the C Programming Language
-
How to write Programs in C (Program
Design Concepts)
1. Introduction
-
A programming language which can be written as either
high level or low level.
-
It is mainly used for writing operating systems, system
programs, graphics applications, and games.
-
Offers flexible. Modular, and open-ended programming
on most types of computers, from PCs to mainframes.
-
C was developed in accord with UNIX (which was written
in C) in 1972 at AT&T's Bell Laboratories by Dennis Ritchie.
-
The C programming language evolved from BCPL through
the B programming language.
2. Virtues of C
a) Design Features
-
it has modern control structures
-
three forms of loops for handling repetitive operations.
-
three structures from choosing alternative paths of action.
-
through its varios types of variables, arrays and other
data structures, C can represent a wide range of information
-
C advocates the use of modules or subroutines (called
functions in C).
-
C makes it simple for you to document your programs by
incorporating explanatory statements.
-
C encourages the programmer to use sound programming
techniques such as top-down planning, structured programming, and modular
design. The result will be a more reliable and understandabke program.
b) Efficiency
-
C is an efficient programming language that allows you
to say what you mean using fewer words.
-
The final code tends to be compact and executes faster.
c) Portability
-
C is a portable language, which means that C programs
written on one computer system can be run with little or no modifications
on other computer systems.
-
C is a leader in portability. C compilers are widely
available for many systems, from 8-bit microprocessors to the mighty mainframes.
d) Power and Flexibility
-
The powerful UNIX operating system was written in C ,
so are many of the supporting programs found on UNIX systems, such as text
editors, compilers and interpreters for other languages like FORTRAN, PASCAL,
LISP, and BASIC.
-
C programs have been used to solve physics and engineering
problems and even for animating movie sequences
-
C has some of the fine control usually associated with
assembly language. For example, in C you are able to manipulate or change
a variable's contents at the bit level.
e) Programmer Orientation.
-
C is oriented to toward programmer needs.
-
It gives access to hardware. It lets you manipulate individual
bits in memory.
-
It has a rich selection of operators.
-
C is less strict. Many operations such as converting
forms of data are simpler in C.
-
C has a large library of useful functions that are generally
available on most C implementations.
3. Writing Programs in C
The act of writing programs in C can be broken down into
seven steps.
a) Define the Program's Objectives
-
start with a clear idea of what the program is supposed
to do.
-
Think generally
-
thin in terms of what information is needed by the program,
what calculations and manipulations the program must do, and output the
program should generate.
b) Design the Program.
-
decide on how the program will go about its implementation.
-
What should the use interface be like? How should the
program be organised?
-
Decide on how to represent the data, and what methods
to use to perform the processing.
-
Use of design principles: step-wise refinement, structured
programming, modular design, and algorithm.
c) Write the Code.
-
Translate program design into the C programming language.
-
Create a source code file which is your program in C
using a text editor.
d) Compile the Code.
-
At this step the source code will be translated into
executable program using a C compiler.
-
The compiler also checks whether your program is valid
C, if it finds any errors, it reports them to you and no executable program
is produced,
e) Run the Program.
-
by running the executable program produced by the compiler,
you can test whether the program runs as expected.
f) Test and Debug the Program.
-
your program may run incorrectly, it may contain bugs
or errors.
-
At this step, any bugs or errors are corrected, and we
go back to step (d).
g) Maintain and Modify the Program.
-
when the program is implemented, users may demand for
new features, or because a undetected bug has surfaced. So, the program
may need to be adapted or corrected and re-tested again.
-
Program maintenance will be greatly simplified if proper
documentation and design was used.