title: Seg fault when using structure pointers to access struct members in C
body: <p>What is wrong with my program, I get seg fault when I try to print the values.</p>
  
  <p>My aim is assign some values in sample_function.</p>
  
  <p>and in main function I want to copy the structure to another structure.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  typedef struct
  {
      char        *name;
      char        *class;
      char        *rollno;
  } test;
  
  test *
  sample_function ()
  {
      test *abc;
      abc = (test *)malloc(sizeof(test));
  
      strcpy(abc-&gt;name,"Microsoft");
      abc-&gt;class = "MD5";
      abc-&gt;rollno = "12345";
  printf("%s %s %s\n",abc-&gt;name,abc-&gt;class,abc-&gt;rollno);
  return abc;
  
  }
  
  int main(){
  
  test   *digest_abc = NULL;
     test   *abc = NULL;
  
  abc = sample_function();
  
  digest_abc = abc;
  printf(" %s  %s  %s \n",digest_abc-&gt;name,digest_abc-&gt;class,digest_abc-&gt;rollno);
  
  return 1;
  
  }
  </code></pre>
  
  <p>Pointer has always been a nightmare for me, I never understood it.</p>