1 / 15

Bab 3 Operator :

Bab 3 Operator :. assignment unary binary ternary. C = 5 + 7. C variabel = operator assignment 5 dan 7 operand 5 + 7 ekspresi + operator aritmetika (penambahan) C = 5+7 statemen aritmetika.

domani
Download Presentation

Bab 3 Operator :

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bab 3Operator : assignment unary binary ternary

  2. C = 5 + 7 C variabel = operator assignment 5 dan 7 operand 5 + 7 ekspresi + operator aritmetika (penambahan) C = 5+7 statemen aritmetika

  3. Operator assignment (=) : operator yang berfungsi untuk memasukan (assign) nilai kedalam suatu variabel atau konstanta. • Operator unary : operator yang hanya melibatkan sebuah operand.

  4. Operator Unary(ex. ch3/code3-3) • Increment (penambahan) • Pre-increment : melakukan penambahan nilai sebelum suatu variabel itu diproses (++C) • Post-increment : melakukan proses terlebih dahulu sebelum dilakukan penambahan nilai (C++) • Decrement (pengurangan) • Pre-increment : -- C • Post-increment : C --

  5. (ex. ch3/code3-3) C = 15; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai --C :"<<--C<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<< endl; C = 20; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai C-- :"<<C--<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<< endl; return 0; } #include<iostream> using namespace std; int main() { int C; C = 5; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai ++C :"<<++C<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<<endl; C = 10; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai C++ :"<<C++<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<< endl;

  6. (ex. ch3/code3-3)

  7. Pre-increment (++C) • Pre-increment adalah melakukan penambahan nilai sebelum suatu variabel itu diproses • Nilai C dinaikkan dahulu sebelum diproses (dalam hal ini ditampilkan di layar) Contoh program: C = 5; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai ++C :"<<++C<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<<endl; Output: Nilai C awal : 5 Nilai ++C : 6 Nilai C akhir : 6

  8. Post-increment (C++) • Post-increment adalah melakukan proses terlebih dahulu sebelum dilakukan penambahan nilai • Nilai dari variabel C harus diproses (ditampilkan) lebih dahulu sebelum nilainya bisa naik. Contoh program: C = 10; cout<<"Nilai C awal:"<<C<<endl; cout<<"Nilai C++ :"<<C++<<endl; cout<<"Nilai C akhir:"<<C<<endl; cout<< endl; Output: Nilai C awal : 10 Nilai ++C : 10 Nilai C akhir : 11

  9. Operator Binary Operator binary: melibatkan dua buah operand, terdiri dari: • Operator Aritmetika • Operator Logika • Operator Relasional • Operator Bitwise

  10. Operator Aritmetika (ex. ch3b/code3-5)

  11. (ex. ch3b/code3-5)

  12. #include <iostream> using namespace std; int main() { int Jumlah; intKurang; int Kali; float Bagi; int Sisa; Jumlah = 2 + 3; Kurang = 5 - 3; Kali = 2 * 3; Bagi = 10.0 / 3.0; Sisa = 10 % 3; cout<<"2 + 3 = "<<Jumlah<<endl; cout<<"5 - 3 = "<<Kurang<<endl; cout<<"2 * 3 = "<<Kali<<endl; cout<<"10.0 / 3.0 = "<<Bagi<<endl; cout<<"10 % 3 = "<<Sisa<<endl; return 0; } (ex. ch3b/code3-5)

  13. Operator Logika: OR (||) Operator Logika: AND (&&)

  14. Operator NOT (!) • Operator NOT: menghasilkan nilai kebalikan • Contoh: !((1&&1)&&(0||1)) Solusi: !((1&&1)&&(0||1)) !(1&&1) !(1) = 0 Ex. Ch3c/code3-10

  15. Operator Relasional

More Related