Outputs addresses and values of array elements. : Array « Data Structure « C++






Outputs addresses and values of array elements.

Outputs addresses and values of array elements.
 



#include <iostream>
using namespace std;
int arr[4] = { 0, 10, 20, 30 };
int main()
{
   cout << "\nAddress and value of array elements:\n"
        << endl;
   for( int i = 0; i < 4; i++ )
      cout << "Address: " << (void*)(arr+i)   // &arr[i]
           << "   Value: " << *(arr+i)        // arr[i]
           << endl;
   return 0;
}


           
         
  








Related examples in the same category

1.Using a Variable Pointer to Point to an ArrayUsing a Variable Pointer to Point to an Array
2.Array InitializationArray Initialization
3.Assigning and Displaying Array ValuesAssigning and Displaying Array Values
4.Using the cin and cout Objects with ArraysUsing the cin and cout Objects with Arrays
5.cin and cout work with char arraycin and cout work with char array
6.To input numbers into an array and output after.To input numbers into an array and output after.
7.Array based on int pointer