I have been learning about using pointers with arrays. If I was to write this simple code:
string Array[3] = {"one", "two", "three"};
string *pArray = Array;
pArray = pArray + 1;
std::cout << *pArray << std::endl;
The output is 'two'
Can someone explain to me the workings of this? Why does the +1 change the position of the pointer to where "two" is in the array? I'd expect the +1 to be concatenated onto the end of the string pointer so I'd end up with something like '0x61feb01'.
How does the compiler know to increment the array and not just add a 1 on to the end of the pointer string memory location?
Why is adding an int to a string different here?
Thanks.