Ch3 Aiman PDF
Ch3 Aiman PDF
Programming
Topic 3: Fundamental of C Programming Language and Basic
Input / Output Function
Fundamental of C and Input /
Output
In this chapter you will learn about:
C Development Environment
C Program Structure
Basic Data Types
Input/Output function
Common Programming Error
Phase 1 Editor
Disk
Program is created using the
Editor and stored on Disk.
Phase 2 Preprocessor
Disk
Pre-processor program
processes the code.
Phase 3 Compiler
Disk
Compiler creates object
code and stores it on Disk.
Phase 5 Loader
Disk
Loader puts Program in
Memory
#include <stdio.h>
int main(void)
{
printf(I love programming\n);
printf(You will love it too once );
printf(you know the trick\n);
return 0;
}
int main(void)
{
double miles;
double kms;
return (0);
}
prepared by NI, edited by MAF
Preprocessor directives
a C program line begins with # provides an instruction to
the C preprocessor
It is executed before the actual compilation is done.
Two most common directives :
#include
#define
In our example
#include<stdio.h> identifies the header file for standard
input and output needed by the printf().
#define KMS_PER_MILE 1.609 informs the preprocessor
that KMS_PER_MILE means 1.609.
return (0);
}
return 0; return 0;
} } } }
int main(void)
{
double miles;
double kms;
return (0);
}
prepared by NI, edited by MAF
The curly braces { }
Identify a segment / body of a program
The start and end of a function
The start and end of the selection or repetition
block.
Since the opening brace indicates the start of
a segment with the closing brace indicating the
end of a segment, there must be just as
many opening braces as closing braces
(this is a common mistake of beginners)
} End of segment
int
main(void)
{
double miles; /*input distance in miles*/
Declarations Comments
double kms; //output distance in kms//
int
used to declare numeric program variables of integer
type
whole numbers, positive and negative
keyword: int
int number;
number = 12;
prepared by NI, edited by MAF
Basic Data Types cont
float
fractional parts, positive and negative
keyword: float
float height;
height = 1.72;
double
used to declare floating point variable of higher
precision or higher range of numbers
exponential numbers, positive and negative
keyword: double
double valuebig;
valuebig = 12E-3; (is equal to 12X10-3)