Algoritma Pemrograman & Struktur Data : Pointer

Kali ini kita akan mendiskusikan tentang Pointer. Untuk materi silahkan unduh disini.

Contoh kode program C++ yang menggunakan ‘pointer’.

#include<iostream>
using namespace std;

int main()
{
int a = 50; // initialize integer variable a
cout<<“Value of ‘a’ = “<<a<<endl; // show the output of a
cout<<“Memory address of ‘a’: “<<&a<<endl; // show the address of a
cout<<endl;

int * b; // declare an integer pointer b
b = &a; // transfer the address of ‘a’ to pointer ‘b’
cout<<“Value of Pointer ‘b’: “<<*b<<endl; // show the output of *b
cout<<“Content of Pointer ‘b’: “<<b<<endl; // show the content of *b
cout<<“Memory address of Pointer ‘b’: “<<&b<<endl; // show the address of *b
cout<<endl;

int **c; // declare an integer pointer to a pointer
c = &b; // transfer the address of ‘b’ to ‘c’
cout<<“Value of Pointer ‘c’: “<<**c<<endl; // show the output of **c
cout<<“Content of Pointer ‘c’: “<<c<<endl; // show the content of **c
cout<<“Memory address of Pointer ‘c’: “<<&c<<endl; // show the address of **c
cout<<endl;
return 0;
}

 

Advertisements

Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: