/***************************************************************
* Name: Prof. Rafael Orta
* Course: Computer Science & Programming
* Class: CS04225
*****************************************************************
* Purpose: Demonstrate the use of Pointers
*****************************************************************/
#include <iostream>
using namespace std;
void output();
int myInt = 0; // Declaring a regular global integer variable
int* intAddress; // Delaring a global pointer of type integer.
int main()
{
intAddress = &myInt; // The pointer now poits to the address of where myInt is being hosted.
*intAddress = 10; // Now I an changing the value that is stored in the address where myInt is being stored.
cout << "The value for myInt is: " << myInt << " and it is stored at : " << &myInt << endl;
cout << "The value for intAddres is: " << *intAddress << " and it is stored at: " << &intAddress << " pointing to :" << intAddress << endl << endl;
output();
return 0;
}
void output(){
cout << "------------------------------------------" << endl;
cout << "| Variable Name | Value | Stored at |" << endl;
cout << "------------------------------------------" << endl;
cout << "| myInt | " << myInt << " | " << &myInt << " |" << endl;
cout << "| intAddress | " << intAddress << " | " << &intAddress << " |" << endl;
cout << "| *intAddress | " << *intAddress << " | " << &intAddress << " |" << endl;
cout << "------------------------------------------" << endl << endl;
cout << "NOTE: Observe the difference between *intAddress, &intAddress and intAddress" << endl;
}