Operator Majemuk
Operator majemuk digunakan untuk memendekkan penulisan operasi penugasan semacam :
                     x = x + 2 ;
                     y = y * 4 ;
menjadi :
                     x += 2;
                     y *= 4;
Contoh program :
//*--------------------------------------------------------------*
//* Contoh 2.5 : penggunaan operator majemuk  
          *//*--------------------------------------------------------------*
#include <iostream.h>
#include <conio.h>
void main()
{
   int x = 2;  // Mula-mula x bernilai 2
   clrscr();    
   cout << “x = “ << x << ‘\n’ ;
   x += 3 ;
   cout << “Setelah x += 3, x = “ << x << ‘\n’ ;
   x *= 2 ;
   cout << “Setelah x *= 2, x = “ << x << ‘\n’ ;
}
Hasil eksekusi:
                    x = 2
                    Setelah x += 3, x = 5
                    Setelah x += 3, x = 5

 
 
 
 
 
 
 

0 komentar:
Speak up your mind
Tell us what you're thinking... !