Last active
September 21, 2017 20:43
-
-
Save myusufid/c9eb5ed3ca07dbd9bbc000119bed8a04 to your computer and use it in GitHub Desktop.
fundamental pointer c++ , thanks materidosen.com & others
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int angka = 90; | |
int *angkax; | |
angkax = &angka; //berisi alamat dari angka | |
cout<<"Nilai (Isi) dari variabel angka : "<<angka; | |
cout<<"\nAlamat Variabel : "<<&angka; //output alamat | |
cout<<"\nNilai Yang ditunjuk : "<<*angkax; //output nilai | |
getchar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int x,y; | |
int *px; | |
x=87; | |
px = &x; //berisi alamat dari x | |
y = *px; //berisi nilai dari x, karna alamat px adalah x | |
cout<<"Alamat X = "<<&x; //output alamat | |
cout<<"\n Isi PX = "<<px; //output alamat | |
cout<<"\n Isi X = "<<x; //output nilai | |
cout<<"\n Nilai yang ditunjuk oleh px = "<<*px; //output nilai | |
cout<<"\n Nilai y = "<<y; //output nilai | |
getchar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
float *x1,*x2,y; | |
y = 13.45; | |
x1 = &y; //berisi alamat | |
x2 = x1; //berisi alamat dari x1 | |
cout<<"Nilai Variabel y = "<<y<<"ada di alamat "<<x1; | |
cout<<"\nNilai Variabel y = "<<y<<"Ada di alamat "<<x2; | |
cout<<"\n Nilai dari X2 = "<<*x2; | |
getchar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//operasi aritmatika pointer, hanya untuk melanjutkan alamat | |
#include <iostream> | |
using namespace std; | |
int main(){ | |
int nilai[3], *penunjuk; | |
nilai[0] = 125; | |
nilai[1] = 345; | |
nilai[2] = 750; | |
penunjuk = &nilai[0]; | |
cout<<"Nilai "<<*penunjuk<<"Ada di alamat memori "<<penunjuk; | |
cout<<"\nNilai "<<*(penunjuk+1)<<"Ada di alamat memori "<<penunjuk+1; | |
cout<<"\nNilai "<<*(penunjuk+2)<<"Ada di alamat memori "<<penunjuk+2; | |
getchar(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//operasi logika dengan pointer | |
#include <iostream> | |
using namespace std; | |
int main(){ | |
int *pa, *pb, a=100,b=10; | |
pa = &a; | |
pb = &b; | |
if(*pa<*pb){ | |
cout<<"Nilai pa lebih rendah dari pb"<<endl; | |
}else if(*pa == *pb){ | |
cout<<"Nilai pa sama dengan nilai pb"<<endl; | |
}else if(*pa > *pb){ | |
cout<<"Nilai pa lebih tinggi dari nilai pb"<<endl; | |
} | |
getchar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment