#include<iostream>
using namespace std ;

int main ()
{
		
	//each memory have their address
	int x = 5 ;
	
	cout << x << endl ;
	cout << &x << endl ;  // pointer kena letak '&' sebelum variable 
	
//ERROR	int *y = x // kena letak '&' dekat x sebab x tu normal
	int *y = &x ;

	cout << "Y = " << y << endl ; 					//address pointed by y (y tu point kat x )
	cout << "Address of Y = " << &y << endl ;  		//address of y 
	cout << "Value pointed by Y = " << *y << endl ;	//the value pointed by y 
	
	int *z = y ;  //naik point sama macam y 
	cout << endl ;
	cout << "Z = " << z << endl ; 
	cout << "Address of Z = " << &z << endl ; 		
	cout << "Value pointed by Z = " << *z << endl ;
	
	int num[3] = {2,4, 6};  //initialise of the array 
	cout << endl ;
	cout << "Address of num = " << num << endl << endl ;  //display address num //num tu num + 0
	cout << "The address of the array " << endl ;
	for (int i = 0; i < 3 ; i++)
	{
		cout <<"Array " << i  << " = " <<  num + i << endl ;  // @  cout << &num[i] << endl ; //nie guna cara array
		cout << "Values of array using pointer " << *(num + i ) << endl ; //*num is value pointed by num
		cout << endl ;
	}
	
	int *p = num + 2 ;  //nak point to the last address  //ni boleh sebab dye array
	cout << p << endl ;
	
	return 0 ;
}
