 <p>You are not initializing p. It's an uninitialized pointer that you are writing to.</p> <p>Since you are writing this in C++, not C, I'd suggest using <code>std::string</code> and <a href="http://www.cplusplus.com/reference/algorithm/reverse/"><code>std::reverse</code></a>:</p> <pre><code>#include &lt;string&gt; #include &lt;algorithm&gt; #include &lt;iostream&gt; int main() { std::string str = "Saw my reflection in snow covered hills"; std::reverse(str.begin(), str.end()); std::cout &lt;&lt; str; return 0; } </code></pre> <p>Output:</p> <pre> sllih derevoc wons ni noitcelfer ym waS </pre> <p>See it working online at <a href="http://ideone.com/iMb1B">ideone</a></p>