Pointer dengan Array

Contoh penggunaan pointer pada C++, dimana nilai pointer didapat dari nilai suatu Array.

#include <iostream.h>

main () {

int x[5]={10,99,23,15,2};
int *px;

cout <<"***********************************" <<endl;
cout <<"| nilai x | nilai px | alamat memori |\n";
cout <<"-------------------------------------------------" <<endl;
for(int i=0;i<=4;i++) {
px = &x[i]; //membaca alamat dari x

cout <<x[i] <<" " <<*px <<" " <<px <<endl;
}
}

Posted in . Bookmark the permalink. RSS feed for this post.

One Response to Pointer dengan Array

Search

Support by Blogger ITN | Converted by LiteThemes.com