I was trying to convert a c++ struct variable to a byte array. But unfortunately, I am getting a weird output.
Code:
#include <bits/stdc++.h>
using namespace std;
struct A{
int x;
};
int main ()
{
A obj;
obj.x = 892323;
char *x =(char *)malloc(sizeof(obj));
memcpy(x, (unsigned char *)&obj, sizeof(obj));
for(int i=0; i < sizeof(obj); i++)
printf("%02X\n",x[i]);
return 0;
}
output:
FFFFFFA3
FFFFFF9D
0D
00
Can anyone tell me why I am getting this kind out output?