Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

1 Komponen Program C bag 1. 2 Topik Type Variables Keywords dan Identifiers Assignments Constant Variables.

Presentasi serupa


Presentasi berjudul: "1 Komponen Program C bag 1. 2 Topik Type Variables Keywords dan Identifiers Assignments Constant Variables."— Transcript presentasi:

1 1 Komponen Program C bag 1

2 2 Topik Type Variables Keywords dan Identifiers Assignments Constant Variables

3 3 Type Macam dr nilai di sebut “type” Tidak semua nilai sama –contoh: 7 + “cat”, sebab beda tipe Value Variable

4 4 Type Built-in types: char, int, float Type modifiers: long, short, const User-defined types (arrays dan record) “strings”? –Strings adalah larik char (nanti di bicarakan)

5 5 Representasi Character Characters disimpan sbg small integer Tiap character punya ekuivalensi dengan unique integer yg di tunjukan pada posisi tabelASCII (“ask-key”) –American Standard Code for Information Interchange

6 6

7 7 Representasi Character Nilai ASCII 0 - 127 –Nilai 0: special character ’\0’ ( NUL character) –nilai 127: special character –special characters lainnya: ’\n’ ’\t’ ’\’’ ’\\’ dll. –Bermacam “extended” char dr 128 - 255

8 8 Variable Nama logikal utk container (tempat nilai di simpan dlm memori) Ber-type, yang di asosiasikan dengannya, yg memberi tahu komputer bgm mengintepretasikan bit Dideklarasikan sebelum di pakai [modifiers] ; [modifiers] = ;

9 9 Variable Declaration: contoh int myID; myID

10 10 Variable Declaration: contoh int myID; char my_initial = ’J’; Single “forward quotes” atau apostrophe ( ’ ) bukan “back quotes” ( ‘ )

11 11 Variable Declaration: contoh int myID; char my_initial = ’J’; 01001010 my_initial

12 12 Variable Declaration: contoh int myID; char my_initial = ’J’; char my_initial = 74 ; 01001010 my_initial

13 13 Variable Declaration: contoh float commission = 0.05; short int myHeight = 165; /* cm */ long int mySalary = 100000000000000000000; long float chanceOfADate = 3e-500; double chance_of_a_2nd_date = 1.5e-500;

14 14 float commission = 0.05; short int myHeight = 165; /* cm */ long int mySalary = 100000000000000000000; long float chanceOfADate = 3e-500; double chance_of_a_2nd_date = 1.5e-500; Variable Declaration: contoh “Keywords”

15 15 Keyword...berarti bagi C …“case-sensitive”...tdk dpt di pakai sbg nama variabel Contoh: int, char, long, main, float, double, const, while, for, if, else, return, break, case, switch, default, typedef, struct, dll

16 16 Variable Declaration: contoh float commission = 0.05; short int myHeight = 165; /* cm */ long int mySalary = 100000000000000000000; long float chanceOfADate = 3e-500; double chance_of_a_2nd_date = 1.5e-500; “Identifiers”

17 17 Identifier...urutan karakter yg tdr dr huruf, angka dan underscores ( _ )...tdk noleh di awali dg angka...bukan KEYWORD …“case-sensitive” Contoh: sUmoFA, x1, y2, _my_ID_, Main (hati-hati!)

18 18 Assignment Peletakan nilai khusus ke suatu variabel Operator Assignment adalah = = ; Berbeda dg ==

19 19 Assignment: Contoh float x = 2.5 ; char ch ; int number ; ch = ’\n’ ; number = 4 + 5 ; /* current value of number is 9. */ number = number * 2; /* current value of number is now 18. */

20 20 Assignment Nilai hrs bertipe spy dpt di assign ke var Nilai otomatis dikonversi ke container contoh: –various.c

21 21 #include /* Do various assignment statements */ int main() { int integer; char character; float floatingPoint; integer = 33; character = 33; floatingPoint = 33; integer = 'A'; character = 'A'; floatingPoint = 'A'; integer = 33.33; character = 33.33; floatingPoint = 33.33; integer = floatingPoint; floatingPoint = integer; return 0; } various.c

22 22 Constant Variables...variabel yang bernilai semacam (tdk berubah)...tidak dpt di assign....HARUS di inisialisasikan const [modifiers] = ;

23 23 Constant Variables: Contoh const int myID = 192; myID = 666; /* Error! */ const int passMark = 80; short char pAsSgRaDe = ’P’; const float e = 3.1415926; /* oops */ const double golden_ratio = 1.61803398874989;

24 24 Konversi sudut dari derajat ke radian output “Masukan sudut dlm derajat ” input angleInDegrees angleInRadians =  / 180 * angleInDegrees output angleInRadians #include /* Konversi sudut dalam derajat ke radian. */ const float PI = 3.1415926; int main() { float angleInDegrees; float angleInRadians; printf(“Masukan sudut dalam derajat : "); scanf("%f", &angleInDegrees); angleInRadians = PI / 180 * angleInDegrees; printf("%f\n", angleInRadians); return 0; } contoh: Constants

25 25 contoh: Constants Variabel “Global” (constant) Variabel “Local” more on this later... #include /* Konversi sudut dalam derajat ke radian. */ const float PI = 3.1415926; int main() { float angleInDegrees; float angleInRadians; printf(" Masukan sudut dalam derajat : "); scanf("%f", &angleInDegrees); angleInRadians = PI / 180 * angleInDegrees; printf("%f\n", angleInRadians); return 0; }


Download ppt "1 Komponen Program C bag 1. 2 Topik Type Variables Keywords dan Identifiers Assignments Constant Variables."

Presentasi serupa


Iklan oleh Google