title: Directly make pointer from ints
body: <p>I was learning about shared memory, and I would like to send an address pointed to a struct variable from one process to another.</p>
  <p>What I did was writing the variable's address into the shared memory, printing the address, then keeping the process alive with an infinite loop. This process will be called process 1. The code:</p>
  <pre><code>    ptr = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, shm_fd, 0);
      sprintf(ptr, &quot;%p&quot;, &amp;temp);
  </code></pre>
  <p>After that, I read the address as a char array from another process (process 2), then I casted it to a long int, with this code</p>
  <pre><code>    sscanf((char*) ptr, &quot;%lx&quot;, &amp;intVal);
  </code></pre>
  <p>then I directly assign a pointer of said struct with this value:</p>
  <pre><code>    student* p = intVal;
  </code></pre>
  <p>but when I try to access the memory region, it produces a Segmentation Fault, although when I run this line</p>
  <pre><code>    printf(&quot;variable A is at address: %p\n&quot;, p);
  </code></pre>
  <p>it prints the exact address from process 1.</p>
  <p>So why does C give segmentation error even when I keep both processes alive?</p>