unsigned is your friend in this case, because char is by default a signed type
if you change some of the types from char to unsigned char you get the correct result:
#include <stdio.h>
void newline(void)
{
putchar('\n');
}
void showbyte(unsigned char *string, int len)
{
int i;
for (i = 0; i < len; i++)
printf("%p\t0x%.2x\n", string+i, *(string+i));
}
int main()
{
int i = 12345;
float f = 1234.5;
double d = 1234.5;
char name[] = "12345";
showbyte((unsigned char *)&i, sizeof i);
newline();
showbyte((unsigned char *)&f, sizeof f);
newline();
showbyte((unsigned char *)&d, sizeof d);
newline();
showbyte((unsigned char *)&name, sizeof name);
return 0;
}
In this case you get:
0x7fff5d5a98b8 0x39
0x7fff5d5a98b9 0x30
0x7fff5d5a98ba 0x00
0x7fff5d5a98bb 0x00
0x7fff5d5a98b4 0x00
0x7fff5d5a98b5 0x50
0x7fff5d5a98b6 0x9a
0x7fff5d5a98b7 0x44
0x7fff5d5a98a8 0x00
0x7fff5d5a98a9 0x00
0x7fff5d5a98aa 0x00
0x7fff5d5a98ab 0x00
0x7fff5d5a98ac 0x00
0x7fff5d5a98ad 0x4a
0x7fff5d5a98ae 0x93
0x7fff5d5a98af 0x40
0x7fff5d5a98a2 0x31
0x7fff5d5a98a3 0x32
0x7fff5d5a98a4 0x33
0x7fff5d5a98a5 0x34
0x7fff5d5a98a6 0x35
0x7fff5d5a98a7 0x00