Introduction To C
Introduction To C
Introduction To C
Compilers
A program that translates the high-level language source code into the detailed
set of machine language instructions the computer requires.
The program does the high-level thinking and the compiler generates the tedious
instructions to the CPU.
Compilers will also check that your program has valid syntax for the
programming language that you are compiling.
o Finds errors and it reports them to you and doesn’t produce an executable
until you fix them.
High-level languages are easier to learn and much easier to program than
machine languages.
Writing a Program
The act of writing a C program can be broken down into multiple steps.
Steps in writing a program
1. Define the program objectives
a. Understand the requirements of the program
b. Get clear idea of what you want the program to accomplish.
2. Design
a. Decide how the program will meet the above requirements
b. What should the user interface be like?
c. How should the program be organized?
3. Write the Code
a. Start implementation, translate the design in the syntax of C
b. You need to use a text editor to create what is called a source code file.
4. Compile
a. Translate the source code into machine code (executable code).
b. Consists of detailed instructions to the CPU expressed in a numeric code.
5. Run the Program
a. The executable file is a program you can run.
6. Test and Debug
a. Just because a program is running, does not mean it works as intended
b. Need to test, to see that your program does what it is supposed to do
(may find bugs)
o Debugging is the process of finding and fixing program errors
o Making mistakes is a natural part of learning.
7. Maintain and Modify the Program
a. Programs are released and used by many people
b. Have to continue to fix new bugs or add new features
For the above steps, you may have to jump around steps and repeat steps
E.g. When you are writing code, you might find that your plan was impractical.
Many new programmers ignore steps 1 and 2 and go directly to writing code
o A big mistake for larger programs, may be ok for very simple programs
o The larger and more complex the program is, the more planning it requires
o Should develop the habit of panning before coding.
Also, while you are coding, you always want to work in small steps and constantly
test (Divide and Conquer).
Overview of C programming Language
C is a general-purpose, imperative computer programming language that
supports structured programming
o Uses statements that change a program’s state, “focuses on how”
In C programming language, you can write Operating System Applications. Also, you
can write general programs.
Currently, it is one of the most widely used programming languages of all time.
C is a modern Language
Has most basic control structures and features of modern languages
Designed for top-down planning
Organized around the use of functions (modular design) structured programming
A very reliable and readable program.
C is used on everything from minicomputers, Unix/Linux systems to pc’s and
mainframes.
C is the preferred language for producing word processing programs,
spreadsheets and compilers.
C has become popular for programming embedded systems.
o Used to program microprocessors found in automobiles, camera, DVD
players and etc.
C has and continues to play a strong role in the development of Linux.
C programs are easy to modify and easy to adapt to new models or languages.
In the 1990’s, many software houses began turning to the C++ language for large
programming projects.
C is a subset of C++ with object-oriented programming tools added
o Any C program is valid C++
o By learning C, you also learn much of C++
C remains a core skill needed by corporations and ranks in the top10 of desired
skills.
C provides constructs that map efficiently to typical machine instructions and thus
is used by programs that were previously implement in assembly language
o Provides low-level access to memory
o Requires minimal run-time support.
History of C language