Working with pointers/adresses

Paul Backus snarwin at
Wed Jul 8 20:33:39 UTC 2020

On Wednesday, 8 July 2020 at 19:48:07 UTC, Quantium wrote:
> I'm learning now memory usage in D, and I have the problem that 
> I can't solve.
> The problem is (The third step):
> 1) Programm gets number (In int format) as input data.
> 2) Integer is converted to HEX
> 3) Programm gets the data in 0x<Integer converted to HEX> 
> memory slot and writes it in the console.

import std.stdio;

void main()
     int i;
     readf("%d\n", i); // read a number
     ubyte* p = cast(ubyte*) i; // convert it to a pointer
     writeln(*p); // write the data at that address to the console

Note that this program will almost certainly crash if you try to 
run it, since modern computers do not allow programs to read and 
write arbitrary memory locations.

More information about the Digitalmars-d-learn mailing list