title: C dynamic allocation malloc struc
body: <p>I'm going through the practicals for my operating systems course and I can't get my head around this example. I've run the program and it does not work. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  typedef struct {
  int age;
  float height;}Person;
  
  void init(Person *);
  int main() {
  
  Person *Callum;
  Callum = malloc(sizeof(*Callum));
  init(Callum);
  printf("Age: %d, height: %f\n", Callum.age, Callum.height);}
  
  void init(Person * individual)
  printf("Age: "); scanf("%d", &amp;(individual-&gt;age));
  printf("Height: "); scanf("%f", &amp;(individual-&gt;height));}
  </code></pre>
  
  <p>I'm going to try to explain what I think is happening and if you could correct my logic I would be very grateful:</p>
  
  <ul>
  <li>We have a pointer called Callum of type Person. </li>
  <li>'Callum = malloc(sizeof(*Callum));' => Does this mean our variable callum has been allocated the memory size of our struct on the heap? </li>
  <li>Person points to our variable Callum. Edit: Sorry I got confused typing it out, I meant individual is pointing to our struc Person.</li>
  <li>The program reads in an input and assigns it to the address of individual, which is the location of our variable Callum. We then print the values of Callum. </li>
  </ul>
  
  <p>Sorry, this is rattling my brain. I know the basic mechanics of a struc and a pointer but I just can't visualize what is happening. Any help would be appreciated. Thank you. </p>