Home » , , » OPERATOR POINTER

OPERATOR POINTER

Written By Unknown on Friday, January 3, 2014 | 12:08 AM

Ada beberapa operator yang bisa digunakan dalam pointer. Operator tersebut adalah operator alamat (yang dilambangkan dengan simbol &) dan operator unary yang mengembalikan alamat dari operandnya.

Sebagai contoh, diasumsikan deklarasi sebagai berikut :
          Int y = 5;
          Int *yPtr;

Maka pernyataan :
          YPtr = &y;

Pernyataan ini mengandung arti bahwa alamat dari variabel y ditujukan kepada variabel pointer yPtr.

Contoh lain :
          Int balance, value;
          Int *balptr;
          Balance = 3200;      // step 1
          Balptr=&balance;    // step 2
          Value=*balptr;        // step 3

Contoh diagram :


Step 1


Step 2


Step 3










12

Balptr
12
100
Balptr
12
100
Balptr









100
3200
Balance
100
3200
Balance
100
3200
Balance









130

value
130

value
130
3200
value












Contoh :

//Program:pointer3.cpp
#include <iostream.h>

int main()
{
int *ptr, num;              // Step 1
ptr = &num;                // Step 2
*ptr = 100;                  // Step 3
cout << num << " ";
(*ptr)++;                      // Step 4
cout << num << " ";
(*ptr)*=2;                    // Step 5
cout << num << "\n";
return 0;
}

Bila program dijalankan :
          100  101  202

Contoh diagram :


Step 1


Step 2


Step 3


Step 4


Step 5
















12
*int
Ptr
12
50
Ptr
12
50
Ptr
12
50
Ptr
12
50
Ptr















50
int
num
50
int
num
50
100
num
50
101
num
50
202
num
















...


...


...


...


...




















Share this article :

0 comments:

Post a Comment

Translate

Popular Posts

Blog Stats

 
Support : Your Link | Your Link | Your Link
Copyright © 2014. Berbagi Ilmu - All Rights Reserved
Template Created by Creating Website Published by T-Ware Template
Proudly powered by Blogger