title: Assigning Value to attribute of struct
body: <p>I am trying to assign value to the attributes of a pointer to a struct, but get Segmentation Faults.</p>
  
  <pre><code>  typedef struct {
      int id;
      char payload[10];
    }packet;
  
    void main(){
     packet *header;
     header-&gt;id = 1;
    }
  </code></pre>
  
  <p>It compiles but it gives me a seg fault when I run it. It only works when I use "malloc" when creating header. Why is that? Normally I don't have to allocate memory for other pointer types.</p>