example of pointer usefulness in D

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 21 13:15:06 PDT 2014


Ali Çehreli:

> - 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;

Regarding this example, this works:

void main() {
     int a, b;
     bool condition;
     (condition ? a : b) = 42;
}

Bye,
bearophile


More information about the Digitalmars-d mailing list