Page 32 - BAHASA PEMROGRAMAN C++
P. 32

OPERA    JENIS OPERASI             CONTOH PEMAKAIAN CODING            HASIL
                               TOR                                                                  OUTPUT
                                  &     AND                  # include <iostream>                 Nilai A = 0
                                        Contoh :  0 AND 1 = 0   using namespace std;
                                                             int main(int argc, char** argv)
                                                             {
                                                                int a = 0 & 1;
                                                                cout<< “Nilai A = “<<a ;
                                                                return 0;
                                                             }
                                  |     OR                  # include <iostream>                   Nilai A = 1
                                        Contoh : 0 OR 1 = 1   using namespace std;
                                                            int main(int argc, char** argv)
                                                            {
                                                               int a = 0 | 1;
                                                               cout<< “Nilai A = “<<a ;
                                                               return 0;
                                                            }
                                  ^     XOR                 # include <iostream>                   Nilai A = 0
                                        Contoh : 1 XOR 1 = 0   using namespace std;
                                                            int main(int argc, char** argv)
                                                            {
                                                               int a = 1^1;
                                                               cout<< “Nilai A = “<<a ;
                                                               return 0;
                                                            }
                                  ~     NOT                 # include <iostream>                   Nilai A = 0
                                        Contoh : NOT 1 =0   using namespace std;
                                                            int main(int argc, char** argv)
                                                            {
                                                               int a = ~1;
                                                               cout<< “Nilai A = “<<a ;
                                                               return 0;
                                                            }
                                 >>     Shift Right         # include <iostream>                   Nilai A = 4
                                        Contoh : 18>>2 =4   using namespace std;
                                                            int main(int argc, char** argv)
                                                            {
                                                               int a = 18>>2;
                                                               cout<< “Nilai A = “<<a ;
                                                               return 0;
                                                            }
                                 <<     Shift Left          # include <iostream>                   Nilai A = 32
                                        Contoh : 16<< 1 = 32  using namespace std;
                                                            int main(int argc, char** argv)
                                                            {
                                                               int a = 16<< 1;
                                                               cout<< “Nilai A = “<<a ;
                                                               return 0;}


                                                                              PEMROGRAMAN C++          25
                                                                                      Bagi Pemula

                                                                                                        25
   27   28   29   30   31   32   33   34   35   36   37