Displaying array elements and their respective memory addresses C++ program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Displaying array elements and their respective memory addresses using pointers in C++ programming
To show: How to print the array memory address in C++ programming using pointers
// a program that uses pointers to print the array elements
#include <iostream>
using namespace std;
void main(void)
{
// declare and initialize an array nums
int nums[ ] = {92,81,70,69,58};
cout<<"\nArray's element Memory address";
cout<<"\n----------------------------------";
// using for loop, displays the elements of nums and their respective memory address
for(int dex=0; dex<5; dex++)
cout<<"\n\t"<<*(nums + dex)<<"\t\t"<<(nums + dex);
cout<<"\n----------------------------------\n";
return;
}
Output example:
Array's element Memory address
----------------------------------
92 0012FF50
81 0012FF54
70 0012FF58
69 0012FF5C
58 0012FF60
----------------------------------
Press any key to continue . . .