How to get data from a memory address stored as an int?

Issue

This Content is from Stack Overflow. Question asked by anom

Is it possible to get the data from a memory address stored as an int?

I’m trying to access the data from a memory address stored as an int. Im then trying to read the data from outside the scope, which i am unsure how to do.

For example:

unsigned int addr;
unsigned int bytes;

template<typename t>
void my_func(t arg)
{
    t* local_args = new t;
    local_args = arg;
    bytes = sizeof(local_args);
    addr = reinterpret_cast<unsigned int>(&local_args);
}


int main()
{
    my_func(5608430536);

    // doesnt work but explains what im trying to do:
    auto i = *reinterpret_cast<char[bytes]*>(addr);
}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?