title: nested structures with pointer in C
body: <p>i want to use nested structures with pointers in c. i write this code but i dont know why this code not working. actually how can i allocate memory for my second structure?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  struct address
  {
      int code;
      char city[10];
  };
  struct student {
      char name[10];
      struct address *ads;
  } *person1;
  
  int main()
  {
  
  person1 = malloc(sizeof(struct student));
  scanf("%s", person1-&gt;name);
  scanf("%d", &amp;person1-&gt;ads-&gt;code);
  scanf("%s", person1-&gt;ads-&gt;city);
  
  printf("%s", person1-&gt;name);
  printf("%d", person1-&gt;ads-&gt;code);
  printf("%s", person1-&gt;ads-&gt;city);
  return 0;
  }
  </code></pre>
  
  <p>NOTE: when i use "person1->ads = malloc(sizeof(struct address));" program ran to problem and stop working.</p>
  
  <hr>
  
  <p>[Update from comment:]</p>
  
  <p>I use DEV C++ v5.4.2</p>