Tuesday, December 6, 2016

Contoh program Pointer

Contoh program Pointer

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x, y; // x dan y bertipe int
int *px; // px pointer yang menunjuk objek


x = 87;
px = &x; // px berisi alamat dari x
y = *px; // y berisi nilai yang ditunjuk px
cout<<"Alamat x pd Memori = "<<&x<<endl;
cout<<"Isi px = "<<px<<endl;
cout<<"Isi x = "<<x<<endl;
cout<<"Nilai yang ditunjuk oleh px = "<<*px<<endl;
cout<<"Alamat y pd Memori = "<<&y<<endl;
cout<<"Nilai y = "<<y<<endl;
getch();

}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,x, y,z;
x=5; y=20; z=8;
cout<<"pilih folder yang ingin dimasuki"<<endl;
cout<<"\n1.gambar"<<endl;
cout<<"\n2.musik"<<endl;
cout<<"\n3.video"<<endl;
cin>>a;
if(a==1) //KONDISI IF
{
cout<<"jumlah gambar "<<x<<""<<endl; // OUTPUT X
cout<<"pada folder ["<<&x<<"]"<<endl; //PENGALAMATAN X
}
else if(a==2) //KONDISI IF
{
cout<<"jumlah musik "<<y<<""<<endl; //  OUTPUT Y
cout<<"pada folder ["<<&y<<"]"<<endl; //PENGALAMATAN Y
}
else if(a==3) //KONDISI IF
{
cout<<"jumlah video "<<z<<""<<endl; // OUTPUT Z
cout<<"pada folder ["<<&z<<"]"<<endl; //PENGALAMATAN Z
}
else //APABILA IF TIDAK TERPENUHI
{
cout<<"pilihan anda salah";
}
getch();  }




No comments:

Post a Comment