On 10/21/2014 05:22 AM, edn wrote:> Could someone provide me with examples showing the usefulness of
> pointers in the D language? They don't seem to be used as much as in C
> and C++.

A pointer is the only sensible option for the following:

- References to any local data because 'ref' is only for parameters and return types.

    int a;
    int b;
    int* r = (condition ? &a : &b);    // r must be a pointer
    *r = 42;

- Any link in a linked data structure like linked lists and trees:

struct L
{
    L* next;    // must be a pointer
}

One can use classes and slices for references as well but they are more expensive.

Ali

Reply via email to