April 17, 2011
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
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
}