Change value of character pointed by a pointer <p>I would like to know why my code giving me error when run.</p> <p>I am trying to change the character value pointed by a pointer variable.</p> <pre><code>#include &lt;stdio.h&gt; int main() { char amessage[] = "foo"; char *pmessage = "foo"; // try 1 amessage[0] = 'o'; // change the first character to '0' printf("%s\n", amessage); // try 2 *pmessage = 'o'; // This one does not work printf("%s\n", pmessage); } </code></pre> <p>The first attempt works, and prints <code>ooo</code>. But the second one gives me:</p> <pre><code>[1] 9677 bus error ./a.out </code></pre> <p>Any ideas?</p>