The output of the above program is -106,Code:#include <stdio.h> #include <string.h> // memcpy #include <iostream> using namespace std; int main () { char *x = new char [20]; unsigned short y = 150; memcpy (x, (const void *)&y, 2); printf ("\n%d\n", x[0]); printf ("\n%d\n", x[1]); }
and when I allocate memory to y and then copy it using memcpy, everything works properly.
but I want to use y without allocating memory to it. What is wrong with the above program ?



LinkBack URL
About LinkBacks



