expression & operator c++

15
7/23/2019 expression & operator C++ http://slidepdf.com/reader/full/expression-operator-c 1/15  expression & operator 

Upload: mwan44

Post on 18-Feb-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 1/15

 

expression & operator 

Page 2: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 2/15

 

Operator arithmetika

+ : penumlahan

 _ : pengurangan

* : perkaliaan

/ : Pembagian% : sisa pembagian

Contoh :

3 + 4 * 5 hasil 33/!" hasil #!5

3/ hasil #

Page 3: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 3/15

 

Contoh program

// program perhitungan

$ inlue 'iostream!h()

nt main,

-  out ''.5 + * 0 1

  '' 5 + *

  ''enl2

  out '' . / + 5 0 1

  '' / + 5''enl2

  out''. /!" + !5 0.

  '' /!" + !5

''enl2

eturn "26

Page 4: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 4/15

 

Operator penambahan an

pengurangan

Contoh :

x 0 x + #2 7ika x nilai 3 sekarang8 maka akan

itambah # men7ai 4 imasukan ke x (g baru

( 0 ( 9 #2 7ika ( nilai 4 sekarang8 maka akan

ikurang # men7ai 3 imasukan ke ( (g baru

apat iganti :

++;;

Page 5: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 5/15

 

Contoh lain :

< 0 x ++ hasiln(a nilai x tertambah # ari

nilai x a=al8 ( sama gn a=al< 0 ++ x hasiln(a nilai ( sama gn nilai x

setelah tertambah #

Page 6: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 6/15

 

Contoh

> a=al pern(ataan ?asil ( ?asil x

4 < 0 x ++2 4 5

4 < 0 ++ x 5 5

4 < 0 x ;; 4 3

Page 7: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 7/15

 

Conntoh penambahan// program penambahan

$ inlue 'iostream!h()

nt main,

- int x8 (2

> 0 42

< 0 9 x ++2

 out ''.ontoh # . ''enl 2

  '' . x 0 . '' x

  '' . ( 0 . '' (  ''enl2

> 0 42

< 0 9 ++ x2

out ''.ontoh . ''enl 2

  '' . x 0 . '' x

  '' . ( 0 . '' (

  ''enl2> 0 42

< 0 9 ; ; x2

out ''.ontoh 3 . ''enl 2

  '' . x 0 . '' x

  '' . ( 0 . '' (

  ''enl2

eturn "2

Page 8: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 8/15

 

Operator bit

& : @n utk biner 

A : Or utk biner 

B : exlusieD : Eot utk biner

'' : geser kiri

)) : geser kanan

Page 9: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 9/15

 

Contoh operator bit &,

Fit # Fit hasil

" " "

" # "

# " "

# # #

Page 10: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 10/15

 

G Contoh lain:

G & #" hasil H

G & hasil 5

#""# """###"#

#"#" & """""### &#""" 0 H """""#"# 0 5

Page 11: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 11/15

 

Contoh operator bit A,

Fit # Fit hasil

" " "

" # #

# " #

# # #

Page 12: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 12/15

 

Contoh operator bit B,

Fit # Fit hasil

" " "

" # #

# " #

# # "

Page 13: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 13/15

 

Operator penugasan

G 0 : pemberian nilai

G + 0 : penambahan bilangan

G ; 0 : pengurangan bilanganG * 0 : Pengalian bilangan

G / 0 : pembagian bilangan

G % 0 : perolehan sisa bagi

Page 14: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 14/15

 

Operator penugasan

utk operasi bit

G & 0 : a &0 x ientik gn a 0 a & x

G B 0 : a B0 x ientik gn a 0 a B x

G A 0 : a A0 x ientik gn a 0 a A xG '' 0 : a ''0 x ientik gn a 0 a '' x

G ))0 : a ))0 x ientik gn a 0 a )) x

Page 15: expression & operator C++

7/23/2019 expression & operator C++

http://slidepdf.com/reader/full/expression-operator-c 15/15

 

Irutan peker7aan operator 

G , iker7akan i alam tana kurung

G * 8 / an % iker7akan lebih ahulu

alam satu baris statement ari kiri ke

kanan

G + an 9 iker7akan kemuian 7ika beraa

paa satu statement