Hi I am having trouble with this code here from a tutorial about returning Arrays from functions
std::string(&func(std::string(&arr)[10]))[10]
{
return arr;
}
int main()
{
std::string array[10] = { "efwefwef","wefffj","mfls","hrkr","sgte","ege","ky","retg","sujtre","fl;yiu" };
std::string* array23 = func(array);
std::cout << array23[0] << std::endl; // why does this work
std::cout << array23[1] << std::endl; // why does this work
}
It compiles fine but I am confused as to how std::string* array23
can be used with the index operator.
I initially thought that this was because std::string
was an array of characters and you could access them individually with the index operator but this next code works and I can not figure out why.
::std::uintptr_t x = 2453;
::std::uintptr_t* pX = &x;
std::cout << "Var: " << pX[0]; // pX prints 2453