Working with pointers/adresses

matheus matheus at
Thu Jul 9 17:24:33 UTC 2020

On Wednesday, 8 July 2020 at 20:33:39 UTC, Paul Backus wrote:
> 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.

I wonder if the question was more like intended to display the 
value using pointers, ie:

import std.stdio;

void main(){
     int i;
     readf("%d\n", i);
     int *p = &i;

Because accessing arbitrary memory location seems very weird.


More information about the Digitalmars-d-learn mailing list