When to Use Pointers
Get to know the scenarios when pointers should be used.
We'll cover the following
Pointers are rare in D. As you have seen in the reading from the standard input lesson, readf
can in fact be used without explicit pointers.
When required by libraries
Pointers can appear on C and C++ library bindings. For example, the following function from the GtkD
library takes a pointer:
GdkGeometry geometry;
// ... set the members of 'geometry' ...
window.setGeometryHints(/* ... */, &geometry, /* ... */);
When referencing variables of value types
Pointers can be used for referring to local variables. The following program counts the outcomes of flipping a coin. It takes advantage of a pointer when referring to one of two local variables:
Get hands-on with 1400+ tech skills courses.