Home > front end >  Getting value of random address location without storing it in a variable
Getting value of random address location without storing it in a variable

Time:02-14

#include<iostream>
using namespace std;


struct node{
    int data;
    node* l,*r;
};


int main()
{
    node* n1 = new node;
    cout<<(n1->l);
    return 0;
}

in the above code I didn't initialize struct data, l and r. so now the address stored in n1->l is CDCDCDCD. Now if I want to see the value stored in that address how to see that without storing the address in a variable.

CodePudding user response:

In general, you can cast any integer to a pointer at your own risk.

node* my_ptr = (node*)0xDEADBEEF;  // Casting to a pointer
node my_node = *(node*)0xDEADBEEF; // Casting to a pointer and dereferencing

The second line is what I believe you want to do "without storing the address in a variable". However that's hacky and useful only in specific contexts, such as DLL injection.

  • Related