0

How can I access the individual memory addresses of elements of a char array? There's almost certainly a misconception in my understanding of what is going on here but I can't figure out what it is.

#include <array>
std::array<char, 10> arr{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
for (int i=0; i<arr.size(); i++){
    cout << i << " " << &i << " " << arr[i] << " " << &arr[i] << " "  << endl;
    }

Produces:

0 0x92f8c0 0 0123456789��� 
1 0x92f8c0 1 123456789��� 
2 0x92f8c0 2 23456789��� 
3 0x92f8c0 3 3456789��� 
4 0x92f8c0 4 456789��� 
5 0x92f8c0 5 56789��� 
6 0x92f8c0 6 6789��� 
7 0x92f8c0 7 789��� 
8 0x92f8c0 8 89��� 
9 0x92f8c0 9 9��� 
CiaranWelsh
  • 6,254
  • 9
  • 43
  • 84

0 Answers0