I just coded a program and now I need to draw a memory map of the results. that shows the address of each variable. Can someone explain to me how to do this with the following code...
#include <iostream>
using namespace std;
//int main function
int main ()
{
//Declare short variables
short int shortVariable1;
short int shortVariable2;
//Declare variables
int normalVariable1;
int normalVariable2;
//Declare long variables
long int longVariable1;
long int longVariable2;
//Declare the pointer variables that store addresses of short ints
short int * shortPtr1;
short int * shortPtr2;
//Declare the pointer variables that store addresses of normal ints
int * intPtr1;
int * intPtr2;
//Declare the pointer variables that store addresses of long ints
long int * longPtr1;
long int * longPtr2;
//Values of short int are addresses of shortVariables
shortPtr1 = &shortVariable1;
shortPtr2 = &shortVariable2;
//Values of int are addresses of normalVariables
intPtr1 = &normalVariable1;
intPtr2 = &normalVariable2;
//Values of long in are addresses of longVariables
longPtr1 = &longVariable1;
longPtr2 = &longVariable2;
//Show results
cout << "&shortVariable1 = " << shortPtr1 << endl
<< "&shortVariable2 = " << shortPtr2 << endl
<< "&normalVariable1 = " << intPtr1 << endl
<< "&normalVariable2 = " << intPtr2 << endl
<< "&longVariable1 = " << longPtr1 << endl
<< "&longVariable2 = " << longPtr2 << endl << endl;
//Calculate the size of the memory allocated to short int
//Subtract addresses of the first and second variable
cout << (shortPtr1 - shortPtr2);
//Calculate the size of the memory allocated to regular int
//Subtract addresses of the first and second variable
cout << (intPtr1 - intPtr2);
//Calculate the size of the memory allocated to regular int
//Subtract addresses of the first and second variable
cout << (longPtr1 - longPtr2);
cout << endl << endl;
return 0;
}