expression & operator c++
TRANSCRIPT
7/23/2019 expression & operator C++
http://slidepdf.com/reader/full/expression-operator-c 1/15
expression & operator
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 #
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
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 :
++;;
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 #
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
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
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
7/23/2019 expression & operator C++
http://slidepdf.com/reader/full/expression-operator-c 9/15
Contoh operator bit &,
Fit # Fit hasil
" " "
" # "
# " "
# # #
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
7/23/2019 expression & operator C++
http://slidepdf.com/reader/full/expression-operator-c 11/15
Contoh operator bit A,
Fit # Fit hasil
" " "
" # #
# " #
# # #
7/23/2019 expression & operator C++
http://slidepdf.com/reader/full/expression-operator-c 12/15
Contoh operator bit B,
Fit # Fit hasil
" " "
" # #
# " #
# # "
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
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
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