Kamis, 07 April 2016

DIKTAT BAB 10.2 C++

#include <iostream>
using namespace std;


class Mhs {
public :
int nim;
char nilai;
};
typedef Mhs *Ptrmhs;
 main() {
Ptrmhs P1, P2, P3;
P1 = new Mhs;
P1->nim = 101;
P1->nilai = 'A';
cout << "P1 : " << P1->nim << " " << P1->nilai << endl;
P2 = new Mhs;
P2 = P1; /* salin alamatnya */
cout << "P2 : " << P2->nim << " " << P2->nilai << endl;
P2->nim = 102;
P2->nilai = 'B';
cout << "P1 : " << P1->nim << " " << P1->nilai << endl;
cout << "P2 : " << P2->nim << " " << P2->nilai << endl;
P3 = new Mhs;
*P3 = *P1; /* salin isinya */
cout << "P1 : " << P1->nim << " " << P1->nilai << endl;
cout << "P3 : " << P3->nim << " " << P3->nilai << endl;
P3->nim = 103;
P3->nilai = 'C';
cout << "P1 : " << P1->nim << " " << P1->nilai << endl;
cout << "P3 : " << P3->nim << " " << P3->nilai << endl;

return 0;
}

Tidak ada komentar:

Posting Komentar