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;
    writeln(*p);
}

Because accessing arbitrary memory location seems very weird.

Matheus.


Reply via email to