title: Assigning (const char *) pointer type - Segmentation fault
body: <p>Below is the representation for <code>Person</code>,</p>
  
  <pre><code>typedef struct{
  
    const char *firstName;
    const char *lastName;
  }PersonDetails;
  
  typedef struct{
  
    const long *sinKey;
    PersonDetails *value;
  }Person;
  </code></pre>
  
  <hr>
  
  <p>where, populating the <code>firstName</code> member creates segmentation fault,</p>
  
  <pre><code>int main(void){
    ....
    Person *person = malloc(sizeof(Person));
    const long key1 =  364222888L;
    printf("Before key assignment\n");
    person-&gt;sinKey = &amp;key1;
    printf("Before first name assignment\n");
    person-&gt;value-&gt;firstName = "Sham";
    printf("Before last name assignment\n");
    person-&gt;value-&gt;lastName = "S";
    ....
  }
  </code></pre>
  
  <hr>
  
  <p><code>const char *firstName</code> holds an immutable string. This immutable string gets stored in <code>.rodata</code> section. <code>firstname</code> can change its pointing location.</p>
  
  <hr>
  
  <p>But, below is the output,</p>
  
  <pre><code>$ ./pq.exe
  ...
  Before key assignment
  Before first name assignment
  Segmentation fault (core dumped)
  </code></pre>
  
  <hr>
  
  <p>How to resolve this problem?</p>