hay friends.....
kali ini saya akan membagikan beberapa koding pointer untuk bahasa c yang kami pelajari beberapa waktu lalu,semoga bermanfaat ea......
contoh 1:
#include<stdio.h>
main()
{
int b,a=50;
int *pointer1;
pointer1 = &a;
b= *pointer1;
printf ("alamat a : %p\n",&a);
printf("isi pointer 1; %p\n",pointer1);
printf("isi a: %d\n",a);
printf("nilai yang di tunjuk oleh pointer1 :%d\n",*pointer1);
printf("nilai dari b :%d\n",b);
getch();
}
contoh 2:
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
int *pointer_x;
int pointee_x=15;
pointer_x=&pointee_x;
printf("nilai pointee_x=%d,pada alamat pointer_x=%p\n",pointee_x,pointer_x);
system("PAUSE");
return 0;
}
#include<stdlib.h>
int main(int argc,char *argv[])
{
int *pointer_x;
int pointee_x=15;
pointer_x=&pointee_x;
printf("nilai pointee_x=%d,pada alamat pointer_x=%p\n",pointee_x,pointer_x);
system("PAUSE");
return 0;
}
contoh 3:
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int nilai1,nilai2,nilai3,*petunjuk,*petunjuk1,*petunjuk2;
nilai1 =123;
nilai2 =456;
nilai3= 789;
//clrcsr();
petunjuk=&nilai1;
petunjuk1=&nilai2;
petunjuk2=&nilai3;
printf("nilai %d dialamat memory %p\n",*petunjuk,petunjuk);
printf("nilai %d di alamat memory %p\n",*(petunjuk1),petunjuk+1);
printf("nilai %d di alamat memory %p\n",*(petunjuk2),petunjuk +2);
getch();
//clrscr();
}
contoh 4:
#include<stdio.h>
#include<conio.h>
int main()
{
int x=20,y;
int *px;
y=x;
px=&x;
*px=35;
printf("nilai dari pa=%d\n",*px);
printf("nilai dari a=%d\n",x);
printf("nilai dari b=%d\n",y);
getch();
}
#include<conio.h>
int main()
{
int x=20,y;
int *px;
y=x;
px=&x;
*px=35;
printf("nilai dari pa=%d\n",*px);
printf("nilai dari a=%d\n",x);
printf("nilai dari b=%d\n",y);
getch();
}
contoh 5
#include<stdio.h>
#include<conio.h>
void main()
{
static int no_rekening[]={5425,8987,53};
int *ptgl;
ptgl =no_rekening;
printf("Diakses melalui pointer\n");
printf("# :%i\n",*ptgl);
printf("# :%i\n",*(ptgl + 1));
printf("# :%i\n\n",*(ptgl + 2));
printf("diakses melalui array biasa\n");
printf("Tanggal : %i\n",no_rekening[0]);
printf("Bulan : %i\n",no_rekening[1]);
printf("Tahun : %i\n",no_rekening[2]);
getch();
}
#include<conio.h>
void main()
{
static int no_rekening[]={5425,8987,53};
int *ptgl;
ptgl =no_rekening;
printf("Diakses melalui pointer\n");
printf("# :%i\n",*ptgl);
printf("# :%i\n",*(ptgl + 1));
printf("# :%i\n\n",*(ptgl + 2));
printf("diakses melalui array biasa\n");
printf("Tanggal : %i\n",no_rekening[0]);
printf("Bulan : %i\n",no_rekening[1]);
printf("Tahun : %i\n",no_rekening[2]);
getch();
}
No comments:
Post a Comment