April 17, 2011 pointers and structures | ||||
---|---|---|---|---|
| ||||
what is the equivalent for this code in D? #include <stdio.h> main() { struct S { int i; }; struct S s, *s_ptr; s_ptr = &s; s_ptr->i = 9; printf("%d\n", s_ptr->i); } |
April 17, 2011 Re: pointers and structures | ||||
---|---|---|---|---|
| ||||
Posted in reply to %u | On 17/04/2011 18:17, %u wrote:
> what is the equivalent for this code in D?
>
> #include<stdio.h>
>
> main()
> {
> struct S { int i; };
> struct S s, *s_ptr;
>
> s_ptr =&s;
> s_ptr->i = 9;
>
> printf("%d\n", s_ptr->i);
> }
import std.stdio;
void main()
{
struct S { int i; }
S s;
S* s_ptr;
s_ptr = &s;
s_ptr.i = 9;
writeln(s_ptr.i); // prints 9
writeln(s.i); // so does this
}
|
Copyright © 1999-2021 by the D Language Foundation