c++ memcpy from a char array to an integer
<p>I am trying to do a <code>memcpy()</code> from a <code>charArray</code> to an integer variable. Copying is done but while trying to print the copied value, some garbage is getting printed. Follow my code. </p>

<p>Is there any issue with padding?</p>

<pre><code>#include &lt;iostream&gt;
#include "string.h"

using namespace std;

int main()
{
    char *tempChar;
    string inputString;
    int tempInt = 3;

    cout &lt;&lt; "enter an integer number" &lt;&lt; endl;
    cin &gt;&gt; inputString;
    tempChar = new char[strlen(inputString.c_str())];   
    strcpy(tempChar, inputString.c_str());  
    memcpy(&amp;tempInt, tempChar, sizeof(int));
    cout &lt;&lt; endl;
    cout &lt;&lt; "tempChar:" &lt;&lt; tempChar &lt;&lt; endl;
    cout &lt;&lt; "tempInt:" &lt;&lt; tempInt &lt;&lt; endl;

    return 0;
}
</code></pre>
