www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pointers and structures

reply %u <asmasm hotmail.com> writes:
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);
        }
Apr 17 2011
parent Christian Manning <cmanning999 gmail.com> writes:
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 }
Apr 17 2011