DLang Notes and Examples
← prev | next →     Top-level ToC     /pointers.html     (printable version)

D supports pointers and they work like you’d expect:

int* x = &y;      // `x` is a pointer to an int, and contains the address of `y`.
// Note:
int* p1, p2, p3;  // All are type pointer to int.

*p derefs the pointer. If you print a pointer, the value is shown in hex.

0.1 The Heap

int* i = new int;  // on the heap
*i = 10;

Note, memory allocated using new is managed by the GC.