how would i go about editing a pointer indirectly?
i want to give the pointer the address to edit at runtime.
eg. the address of 0x65456 = 15
int* addr;
cin>>addr;
*addr = 20
cout<<*addr
runtime:
input: 0x65456
output: 20
indirectly edioting a pointer c++
Re:indirectly edioting a pointer c++
Afaik, you can use the C or C++ type casting (don?t know much on the latter).
So:
A pointer is 4 bytes and int or unsigned int are 4 bytes long; generally try to learn on casts.
Cheers ;D
So:
Code: Select all
int * ptr;
(int)ptr= 0x66665;
cin >> (int)ptr;
cout << ?the pointer points at ? << (int)ptr << " and at that place im memory, we?ve got the int ? << *ptr << endl;
(unsigned int) ptr=0x12345678;
(char) ptr= 0x2f; //equivalent to setting (int)ptr=0x0000002f
(char)ptr=0x80; //equivalent to setting (int)ptr=0xffffff80 for bit copying- corrections welcome!
Cheers ;D
Re:indirectly edioting a pointer c++
No, a pointer is not necessarily 4 bytes, and neither is an int.Adek336 wrote: A pointer is 4 bytes and int or unsigned int are 4 bytes long; generally try to learn on casts.
The C99 header <stdint.h> provides the intptr_t typedef, which defines an integer that can be cast to a void *. That's the only "safe" way to play it unless you do some autoconf trickery to find out the correct integer type yourself. Unfortunately C++ doesn't define <stdint.h>.
Every good solution is obvious once you've found it.