0
#include <iostream>

int main()
{
    char myName[]{ "Alex" }; // fixed array
    std::cout << myName << '\n';

    return 0;
}

The output of the above code is: Alex

On the other hand, the output of the following code

int main()
{
     int array []{ 9, 7, 5, 3, 1 };

     std::cout << array << '\n'; // print memory address of array pointer 
 }

is: 0x7ffdf3e66f50 I understand both and then was confused at the same time. So I need more clarifications.

kkxx
  • 571
  • 1
  • 5
  • 16
  • possible duplicate https://stackoverflow.com/questions/1461432/what-is-array-decaying – Andrew Kashpur Nov 20 '19 at 14:47
  • 1
    I'm not sure I understand your second example. How did you determine that it "print memory address of array pointer + 1", I've compared variations (`&array`, `array` and `&array[0]`) and they had all the same value. – AProgrammer Nov 20 '19 at 14:48
  • @AProgrammer, I have updated it. I mean, print the memory address of the decayed array pointer, which is the memory address of array[0], which is 0x7ffdf3e66f50. What confused me is that, the first one print out the value of the array, which is "Alex"; while the second one prints out the memory address of the first element of the array. – kkxx Nov 20 '19 at 17:59
  • Ok, the duplicate should then answer your question. – AProgrammer Nov 20 '19 at 19:19

0 Answers0