Mam taki kod:
#include <iostream>
void fun()
{
int x;
int y;
std::cout << std::hex << "0x" << reinterpret_cast<unsigned*>(&x) << std::endl;
std::cout << std::hex << "0x" << reinterpret_cast<unsigned*>(&y) << std::endl;
}
int main()
{
fun();
return 0;
}
Output:
0x0x7ffec0fe3da0
0x0x7ffec0fe3da4
Zgodnie z teorią stos rośnie w dół czyli wirtualny adres funkcji main() jest najwyższy ze wszystkich adresów funkcji w user spejcie dla danego programu. I podobnie ze zmiennymi najpierw x leci na stos a potem y. Więc spodziewałbym się że adres x-a będzie większy od adresu y-a a tak nie jest. Ale przynajmniej dla funkcji się zgadza adres main jest wyższy niż adres fun.