With this code:
#include <stdio.h>
#include <unistd.h>
int main()
{
char buffer[64];
int check;
int i = 2;
buffer[-2] = i;
printf("%x\n",buffer[-2]);
i=25;
buffer[-2] = i;
printf("%x\n",buffer[-2]);
i=255;
buffer[-2] = i;
printf("%x\n",buffer[-2]);
return 0;
}
I get this output (compilation with gcc and -m32
option).
2
19
ffffffff
So, I can understand the two first values (2 and 19), but I really don't understand the 3rd as 255 is equal to ff and not ffffffff.
Do you have any idea why it's displayed like this ?
Thank you
p.s: Please don't suggest to affect "chars" to a "char" array, this code is just for training, thank you.
p.s (bis): please don't say it's not valid, because if it is, why are the 1rst two output of the program in accordance with the code ??
I compiled this code with gcc -m32 -o code code.c