Sei sulla pagina 1di 26

Malaysian Institute of Aviation Technology

Malaysian Institute of Aviation Technology

• No programming experience is
assumed
• This course will cover topics
from introductory to Advanced
level
Malaysian Institute of Aviation Technology

• Procedural - natural top-down planning,


structured programming and modular
design - more reliable, understandable
program
• Multi-plateform/ portable
• Powerful & flexible but complex
• Programmer oriented – C retains the
basic philosophy that programmers know
What they are doing
Malaysian Institute of Aviation Technology

What is a program?

• A list of instructions.
• Written in a programming language (c, c++,
java).
• Determines the behavior of a machine
(computer, robot).
Malaysian Institute of Aviation Technology

Programming Language

• A machine language that has its own set


of grammatical rules.
• It is used to instruct a machine to perform
specific tasks.
Malaysian Institute of Aviation Technology

History
• C was developed in 1972 by Dennis
Ritchie at Bell Laboratories.
• Based on a programming language called
B (which is derived from BCPL language).
• C was designed and developed for the
development of UNIX operating system.
• C has been widely used to develop many
type of application software from a basic to
operating system.
Malaysian Institute of Aviation Technology

• “Kernighan and Ritchie” C


• ANSI C
• C++
• C#, JAVA
Malaysian Institute of Aviation Technology

Development
stages of C
program
Malaysian Institute of Aviation Technology

Editing
• Process of writing the C source code.
• Using editor program (i.e. vi and emacs for
Linux, Notepad for Windows)
• Software package provides programming
environment
– Integrated editor
– Managing and maintaining source code
– i.e. C++ Builder, Code::Blocks, Dev-C++,
Microsoft Visual Studio
Malaysian Institute of Aviation Technology

Pre-processing and Compiling

• Pre-processing – performs directives such


as inclusion of header files and
substitution.
• Compiling – process of translating the
source code (programming language) to
machine code (machine language).
Malaysian Institute of Aviation Technology

Linking

• Process of combining generated object


files.
• Add required codes from C standard
library.
• Produce an executable file.
Malaysian Institute of Aviation Technology

Executing

• Run the program to check whether it


produce the desired output.
• Testing stage where you check the output
of your program.
• The program does not produces the
suppose output, then you have made logic
(semantic) error.
Malaysian Institute of Aviation Technology

C Program Layout
• C program consists of two sections:
– Pre-processor directives
– Main function
/* an example of C program */
#include <stdio.h> Pre-processor directives

/*main function definition */


int main() Main Function
{
statements;
}
Malaysian Institute of Aviation Technology

Pre-processor Directives

• Specify what compiler should do before


compilation.
• Include header files.
• Header file keep information about the
library functions (printf, scanf).
• Pre-processor directives begins with the #
symbol.
Malaysian Institute of Aviation Technology

Main Function

• The program starts its execution.


• Define the program definition.
Malaysian Institute of Aviation Technology

An Example of C Program

Sample output:
C program example
Malaysian Institute of Aviation Technology
Malaysian Institute of Aviation Technology

1. Coding
2. Compiling
3. Testing (running and debugging)
4. If problem, repeat 1-3 again

An Integrated Development Environment (IDE) or separate (usually


command-line) tools?
Malaysian Institute of Aviation Technology
Malaysian Institute of Aviation Technology

• In This Chapter:
i) We creat our ‘FIRST C” PROGRAM
ii) We discover variable.
iii) We learn about the function of printf, scanf and
getchar
Malaysian Institute of Aviation Technology

• Variable are small, named pieces of


memory that can assigned values
• These values can change
• Variables can thought of as “boxes” that
can contain “contents”
Malaysian Institute of Aviation Technology

• Variable has unique names


• Names can only contain the characters:
– a-z, A-Z, 0-9, “_”
• Names must not begin with a digit
Malaysian Institute of Aviation Technology

Declaring an answer and assigning it value


Malaysian Institute of Aviation Technology

• One common type of variable is the int –


the integer
• Variable must be set (initialised) before
they can be read
• Variables are assigned values by use of
the “=“
Malaysian Institute of Aviation Technology

• Variables must be declared before they


can be used
• Only declared at the top of the function
• Variables are declared as follows:
Type-name variable-name;
Malaysian Institute of Aviation Technology

• Write a program that asks the user two


questions:
– How many brothers and sisters do you have
– How many children that you plan to have
• What does scanf do if you don’t enter digits in
response to the question?
• Try coding your scanf program without using &

Potrebbero piacerti anche