-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6.Replace_Pointer.cpp
More file actions
23 lines (22 loc) · 707 Bytes
/
6.Replace_Pointer.cpp
File metadata and controls
23 lines (22 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main (){
//membuat sebuah variabel
string mobil = "Mazda";
//disini kita membuat sebuah variabel yang berisi pointer dari variabel mobil
string *PointerMobil = &mobil;
//output biasa
cout<<mobil<<endl;
//output nilai dari pointer
cout<<PointerMobil<<endl;
//dereferensi pointer
cout<<*PointerMobil<<endl;
//kita Replace alamat memori sebelumnya dengan value ini
*PointerMobil = "BMW";
//nilai value di alamat memori ter replace dan variabel asli pun akan terganti
cout<<*PointerMobil<<endl;
cout<<mobil<<endl;
//alamat memori yang masih sama
cout<<PointerMobil;
//Keep Spirit Devs ! ^-^
}