Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are doing it except on your system you cannot write to this memory causing a segmentation fault.</p> <p>A segmentation fault (often shortened to segfault), bus error or access violation is generally <strong>an attempt to access memory that the CPU cannot physically address</strong>. It occurs when the hardware notifies an operating system about a memory access violation. The OS kernel then sends a signal to the process which caused the exception. By default, the process receiving the signal dumps core and terminates. The default signal handler can also be overridden to customize how the signal is handled.</p> <p>If you are interested in knowing more look up MMU on wikipedia.</p> <p>Here is how to legally request memory from the heap. The <code>malloc()</code> function takes a number of bytes to allocate as a parameter. Please note that every <code>malloc()</code> should be matched by a <code>free()</code> call to that same memory after you are done using it. The <code>free()</code> call should normally be in the same function as where you called <code>malloc()</code>.</p> <pre><code>#include &lt;stdio.h&gt; int main() { int val; char *a; a = (char*)malloc(sizeof(char) * 1); *a = 20; val = (int)*a; printf("%d", val); free(a); return 0; } </code></pre> <p>You can also allocate memory on the stack in a very simple way like so:</p> <pre><code>#include &lt;stdio.h&gt; int main() { int val; char *a; char b; a = &amp;b; *a = 20; val = (int)*a; printf("%d", val); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload