/***************************************************************
* Name: Prof. Orta
* Course: Computer Science & Programming
* Class: CS04103 Section: 1 & 2
* Assignment Date: 11/04/20
* File Name: Pointers.cpp
*****************************************************************
* ID: Chapter 10
* Purpose: Demonstrating the use of pointer
*****************************************************************/
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
cout << "\n\n********************** Remembering memory references *********************" << endl << endl;
int x = 20;
cout << "\nThe variable x has a value of " << x << " and is stored in the hexadecimal memory location: " << &x << " which translates to: " << long(&x) << " decimal."<< endl;
cout << "\n\n********************** Arrays relationship with pointers *********************" << endl << endl;
int array[3]={5,10,20};
cout << "The position 0 of the array has a value of: " << array[0] << " and is stored in the memory location: " << &array[0] << endl;
cout << "Notice that the array name is a pointer to the first value of the array and it points to: " << &array;
cout << "\n\n********************************* Pointers ******************************" << endl << endl;
int *intptr; // Creating a pointer that points to an integer value, in other words it stores the memory location of an integer.
intptr = &x; // Assigning to the pointer the memory address of x
cout << "\nThe pointer intptr has a value of " << *intptr << " and is stored in the hexadecimal memory location: " << intptr << " which translates to: " << long(intptr) << " decimal."<< endl;
cout << "\n\n****************************** Re-using a Pointer ******************************" << endl << endl;
intptr = array;
cout << "\nThe pointer intptr has a value of " << *intptr << " and is stored in the hexadecimal memory location: " << intptr << " which translates to: " << long(intptr) << " decimal."<< endl;
intptr = array+1;
cout << "The pointer intptr has a value of " << *intptr << " and is stored in the hexadecimal memory location: " << intptr << " which translates to: " << long(intptr) << " decimal."<< endl;
cout << "The pointer intptr has a value of " << *(intptr+2) << " and is stored in the hexadecimal memory location: " << *(intptr+2) << " which translates to: " << long(intptr+2) << " decimal."<< endl;
return 0;
}