3. DAFTAR PUSTAKA
SAM PUBLISHING, TEACH YOURSELF
C IN 21 DAYS
OXFORD UNIVERSITY COMPUTING
SERIES ,PROGRAMMING IN C
BRIAN W.KERNIGHAN AND DENNIS
M. RICHIE ,The C programming
Language, PRENTICE HALL 1988
6. PENDAHULUAN
MENGAPA MENGGUNAKAN C
SALAH SATU BAHASA PEMROGRAMAN GENERASI
KETIGA YANG PALING BANYAK DIGUNAKAN
KEMAMPUANNYA DAN FLEKSIBILITASNYA MEMBUAT
C MASIH MENJADI PILIHAN UNTUK HAMPIR SEMUA
BIDANG APLIKASI KHUSUSNYA PADA LINGKUNGAN
PENGEMBANGAN PERANGKAT LUNAK
BANYAK APLIKASI DITULIS DALAM C ATAU C++
TERMASUK COMPILER UNTUK BAHASA
PEMROGRAMAN LAIN
BANYAK SISTEM OPERASI DITULIS DIDALAM BAHASA
C TERMASUK UNIX, DOS DAN WINDOWS
7. MENGAPA C
BERADAPTASI DENGAN PENGGUNAAN BARU DAN YANG
TERAKHIR ADALAH JAVA YANG DIGUNAKAN UNTUK
PEMROGRAMAN APLIKASI INTERNE T
MEMPUNYAI BANYAK KEKUATAN ( KEUNTUNGAN )
SEPERTI : FLEKSIBEL DAN PORTABEL ,MENGHASILKAN
DENGAN CEPAT, KODENYA COMPACT, BERORIENTASI
OBYEK UNTUK MEMBUAT DAN MEMANIPULASI STRUKTUR
YANG KOMPLEKS (CLASS DALAM C++),MEMPUNYAI
RUTIN-RUTIN TINGKAT RENDAH UNTUK MENGONTROL
PERANGKAT KERAS ( CONTOH : PORT INPUT DAN OUTPUT
DAN SISTEM OPERASI INTERUPSI ),MEMPUNYAI STANDAR
INTERNASIONAL ANSI C
10. KOMPONEN-KOMPONEN BAHASA C
HEADER FILES ( stdio.h )
PREPROCESSOR DIRECTIVE ( # include )
FUNGSI UTAMA ( main ( ) )
KURUNG KURAWAL BUKA DAN TUTUP ( { } )
VARIABEL
PERNYATAAN
KOMENTAR
RETURN
14. PENGENAL
DIGUNAKAN SEBAGAI NAMA VARIABEL , FUNGSI ,
KOMSTANTA
SYARAT-SYARAT PENGENAL :
KARAKTER PERTAMA HARUS HURUF ATAU GARIS
BAWAH
KARAKTER SELANJUTNYA BISA HURUF,ANGKA ATAU
GARIS BAWAH
TIDAK BOLEH MENGGUNAKAN KATA KUNCI
PANJANG KARAKTER 35
UNIK
15. DEKLARASI & INISIALISASI VARIABEL
Deklarasi variabel : int x,y,z;
Inisialisasi variabel : int x = 24;
int i,j;
char ch;
double x,y,z,fred;
unsigned long int Name_of_Variable;
16. Hello World Program
The source code
#include <stdio.h>
int main()
{
printf("Hello Worldn");
return(0);
}
17. Data types
Name
Description
Size*
Range*
char
Character or small
integer
1 byte
signed: -128 to 127
unsigned: 0 to 255
short int
(short)
Short integer
2 bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int
Integer
4 bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
long int
(long)
Long integer
4 bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
float
Floating point
number
4 bytes
3.4e +/- 38 (7 digits)
double
Double precision
8 bytes
floating point number
1.7e +/- 308 (15 digits)
long
double
Long double
precision floating
point number
1.7e +/- 308 (15 digits)
8 bytes
18. Variable types
Local variabel
Local variabel digunakan didalam suatu fungsi , dan hanya
digunakan didalam fungsi tersebut .
Static variabel
Ditentukan dengan suatu keyword static pada deklarasi variabel.
Perbedaan dari non-static local variable adalah variabel static
tidak bisa dihilangkan dengan keluar dari fungsi.
Global variabel
Suatu deklarasi global variable kelihatannya normal, tetapi terletak
diluar suatu fungsi program . Oleh karena itu ia bisa di akses oleh
semua fungsi .
23. INC/DEC
PRE INCREMENT ( ++ X)
POST INCREMENT ( X++)
PRE DECREMENT ( --X )
POST DECREMENT ( X--)
24. Example
Arithmetic operators
int i = 10;
int j = 15;
int add = i + j; //25
int diff = j – i; //5
int product = i * j; // 150
int quotient = j / i; // 1
int residual = j % i; // 5
i++; //Increase by 1
i--;
//Decrease by 1
26. The Answer
j / i = 1;
j % i = 5;
k / i = 1.5;
k % i It is illegal.
Note: For %, the operands can only be integers.
27.
28.
29. The Answer
j / i = 1;
j % i = 5;
k / i = 1.5;
k % i It is illegal.
Note: For %, the operands can only be integers.
30. OPERATOR LOGIKA &
RELASI
What is “true” and “false” in C
In C, there is no specific data type to represent “true” and “false”. C
uses value “0” to represent “false”, and uses non-zero value to stand
for “true”.
Logical Operators
A && B
=>
A || B
=>
A == B
=>
A != B
=>
A and B
A or B
Is A equal to B?
Is A not equal to B?
31.
32. A >B
A >= B
A <B
A <= B
=>
=>
=>
=>
Is A greater than B?
Is A greater than or equal to B?
Is A less than B?
Is A less than or equal to B?
Don’t be confused
&& and || have different meanings from & and |.
& and | are bitwise operators.
37. int i = 10; int j = 15; int k = 15; int m = 0;
if( i < j && j < k) =>
if( i != j || k < j) =>
if( j<= k || i > k) =>
if( j == k && m) =>
if(i)
=>
if(m || j && i )
=>
38. int i = 10; int j = 15; int k = 15; int m = 0;
if( i < j && j < k) => false
if( i != j || k < j) => true
if( j<= k || i > k) => true
if( j == k && m) => false
if(i)
=> true
if(m || j && i )
=> true
Did you get the correct answers?
46. printf()
Fungsi printf() dapat diperintahkan untuk mencetak
integers, floats and string .
syntax yang umum adalah
printf( “format”, variabel);
Contoh :
int stud_id = 5200;
char * name = “Mike”;
printf(“%s ‘s ID is %d n”, name, stud_id);
47.
48.
49.
50.
Why “n”
It introduces a new line on the terminal screen.
escape sequence
a
b
f
n
r
t
v
alert (bell) character
backspace
formfeed
newline
carriage return
horizontal tab
vertical tab
?
’
”
000
xhh
backslash
question mark
single quote
double quote
octal number
hexadecimal number
51.
Format Identifiers
%d
decimal integers
%x
hex integer
%c
character
%f
float and double number
%s
string
%p
pointer
How to specify display space for a variable?
printf(“The student id is %5d n”, stud_id);
The value of stud_id will occupy 5 characters space in the
print-out.
70. PERNYATAAN
PENGULANGAN FOR
for statement
for (expression1; expression2; expression3){
statement…
}
expression1 initializes;
expression2 is the terminate test;
expression3 is the modifier;
74.
An example
int x;
for (x=0; x<3; x++)
{
printf("x=%dn",x);
}
First time:
x = 0;
Second time:
x = 1;
Third time:
x = 2;
Fourth time:
x = 3; (don’t execute the body)
82.
The while statement
while (expression) {
statement …
}
while loop exits only when the expression is false.
An example
int x = 3;
while (x>0) {
printf("x=%d n",x);
x--;
}
83.
84.
85.
86.
87. for <==> while
for (expression1;
expression2;
expression3){
statement…
}
equals
expression1;
while (expression2)
{
statement…;
expression3;
}
101. PERNYATAAN BREAK
PERNYATAN YANG DIGUNAKAN
UNTUK KELUAR DARI SUATU
PERNYATAAN PENGULANGAN
PERNYATAAN YANG DIGUNAKAN
DIDALAM SWITCH UNTUK
MENGAKHIRI SUATU PILIHAN
118. PERNYATAAN NULL
Jika anda meletakkan tanda titik koma pada
suatu baris , anda membuat suatu
pernyataan null
yaitu suatu pernyataan yang tidak
melakukan suatu aksi apapun.
Syntax
:
;
119. PERNYATAAN MAJEMUK
Suatu pernyataan majemuk disebut juga
block, block adalah sekelompok dua atau
lebih
pernyataan diantara dua kurung
kurawal.
Contoh
:
127. FUNGSI
FUNGSI ADALAH SEKELOMPOK
PERNYATAAN PERNYATAAN YANG
BERSAMA-SAMA MELAKUKAN TUGAS
FUNGSI DISEBUT JUGA SUBRUTIN
/SUBPROGRAM
CIRI-CIRI FUNGSI:MEMPUNYAI NAMA,
INDEPENDEN,MELAKUKAN SUATU TUGAS
KHUSUS,DAPAT MENGEMBALIKAN
SUATU NILAI KE PROGRAM
PEMANGGILNYA
144. ARRAY/LARIK
LARIKARRAY ADALAH SEKUMPULAN
VARIABEL YANG MEMPUNYAI NAMA SAMA
TETAPI INDEKSNYA BERBEDA
SETIAP VARIABEL YANG TERDAPAT DIDALAM
SUATU LARIKARRAY DISEBUT ELEMEN DARI
LARIK TERSEBUT
JENIS LARIKARRAY DIDALAM C TERBAGI
ATAS : DIMENSI SATU, DIMENSI DUA , DIMENSI
TIGA
147. MENGAKSES ELEMEN
SUATU LARIKARRAY
SUATU ELEMEN LARIK DAPAT
DIAKSES DENGAN MEMBERIKAN
INDEKS ELEMEN SETELAH NAMA
LARIKARRAY
double salary = balance [ 9 ] ;
179. MEMANIPULASI STRING
MENENTUKAN PANJANG SUATU
STRING
MENGCOPY DAN
MENGGABUNGKAN STRING
MEMBANDINGKAN STRING
MENCARI STRING
MENGUBAH STRING
MENGUJI KARAKTER
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192. Books recommended
The C Programming Language, Brian Kernighan
and Dennis Ritchie. Second edition. Prentice-Hall,
1988. (C Bible)
The C++ Programming Language, Bjarne
Stroustrup. Third edition. Addison-Wesley, 1997.
(C++ Bible)
Advanced Programming in the UNIX
Environment, W. Richard Stevens, AddisonWesley, 1992. (APUE)