Multiple errors.
1) Main must return an int. Not void. Ever.
2) You pass &memory to the first memcpy -- that isn't what you want; memory is already a pointer. You're trying to pass a pointer to the buffer, not a pointer to a pointer to a buffer. The first memcpy will trash your stack.
3) You allocate memory you do not free.
Additionally,
4) You use a global variable without cause.
5) Your memory buffer might be too small -- you are not allowed to make assumptions about sizeof(float), if it's greater than 6, you buffer overflow.
6) You deliberately circumvent the C++ type checking system without a reason.
Code:
#include <stream.h> // Header file i made that just has the basic includes for doing random dos stuff
unsigned char* memory;
int main()
{
memory=new unsigned char[6];
float test=-7;
memcpy(memory,&test,sizeof(float));
float test2=0;
memcpy(&test2,memory,sizeof(float));
printf("%f",test2);
delete[] memory;
}
But the better way to do this is:
Code:
#include <stream.h> // Header file i made that just has the basic includes for doing random dos stuff
int main()
{
float * memory=new float;
float test=-7;
*memory = test;
float test2=0;
test2 = *memory;
printf("%f",test2);
delete memory;
}