Operator Majemuk c++

Selasa, 20 Maret 2012

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


Share this article :

0 komentar:

Speak up your mind

Tell us what you're thinking... !

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kunci Nemu - All Rights Reserved
Template Created by Creating Website Inspired by Sportapolis Shape5.com
Proudly powered by Blogger