// Array pointer demo
// Date 23:21 25/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
using namespace std;
using std::cout;
using std::endl;

void Display(int *d, int size){
	int *ptr = d;
	int i = 0;
	while (i < size){
		//Print out the item using the address of the array contents
		cout << *ptr << " ";
		*ptr++;
		i++;
	}
	cout << endl;
}

int main(int argc, char *argv[]){
	int nums[6] = { 10, 20, 30, 40, 50,60 };
	int *ptr;
	int i = 0;
	int len = sizeof(nums) / sizeof(int);

	cout << "P O I N T E R S  -  D E M O" << endl;

	cout << "Original : ";
	Display(nums, len);
	cout << endl << "Editing array data tho a pointer adding 5 to each number" << endl;

	ptr = nums;
	while (i < len){
		*ptr += 5;
		ptr++;
		i++;
	}

	Display(nums, len);

	cout << endl << "Edit first and last element with 256" << endl;

	//Get address
	ptr = &nums[0];
	//Set item data using the address
	*ptr = 256;

	//Get address
	ptr = &nums[len - 1];
	//Set item data using the address
	*ptr = 256;

	Display(nums, len);

	system("pause");
	return 0;
}