Operator Pada C Amaludin Arifia, M.Kom
Pembahasan Operator Aritmatika Operator Relasi Operator Logika
Operator Aritmatika Capture by How to C program 6th edition Deitel
Precedence in Logical Operation Operator Operation Order of evaluation (precedence) ( ) Parentheses Evaluated first If the parentheses are nested,the expression in the innermost pair is evaluated first. If there are several pairs of parentheses “on the same level” (not nested), they’re evaluated left to right. * Multiplication Evaluated second. If there are several, they’re evaluated left to right. / Division % Modulus + Addition Evaluated last. If there are several, they’re evaluated left to right. - Subtraction
Aturan precedence Operator didalam parenthese“()” akan di evaluasi Paling Pertama oleh compiler C highest level of precedence Multiplication, division and remainder Operator ini akan dikerjakan setelah oprator “()” jika tidak ada maka akan dikerjakan pertama kali. jika terdapat banyak operasi, akan dikerjakan dari kiri ke kanan Addition and subtraction operations dikerjakan setelah Multiplication, division and remainder.
Example Y = A * X * X + B * X + C; Step 1. Y = 2 * 5 * 5 + 3 * 5 + 7; 2 * 5 is 10 Step 2. Y = 10 * 5 + 3 * 5 + 7; 10 * 5 is 50 Step 3.Y = 50 + 3 * 5 + 7; 3 * 5 is 15 Step 4. Y = 50 + 15 + 7; 50 + 15 is 65 Step 5. Y = 65 + 7; 65 + 7 is 72 Step 6. y = 72
Equality dan Operator Relasi
Equality dan Operator Relasi Digunakan untuk Decission Statemen ( statemen keputusan ) ?
Example To determine if a student’s grade on an exam is greater than or equal to 60 and if it is to print the message “Congratulations! You passed.” in C If(exam>=60) { printf(“Congratulations! You passed”); } else {(“Sorry you must study hard”); } Akan kita jumpai pada penggunaan IF, else, else if statemen. Hasil ungkapan akan bernila true atau false True jika memenuhi ungkapan false jika tidak memenuhi ungkapan.
Operator Logika && (logical AND), || (logical OR) dan ! (logical NOT also called logical negation)
Terima Kasih