https://bbs.csdn.net/topics/390514117
#include <stdio.h>
int print_all_byte(void *addr, int size)
{
unsigned char *ptr = addr;
int print_bytes = 0;
if(NULL == ptr) {
return -1;
}
while(print_bytes < size) {
printf("%02x", *ptr);
ptr++;
print_bytes++;
}
printf("\n");
return print_bytes;
}
int main(void)
{
int d1 = 0x12345678;
long d2 = 0x87654321;
double d3 = 0.12345678;
int arr1[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 1234};
if(sizeof(d1) == print_all_byte((void *)&d1, sizeof(d1))) {
printf("print int success!\n");
}
if(sizeof(d2) == print_all_byte((void *)&d2, sizeof(d2))) {
printf("print long success!\n");
}
if(sizeof(d3) == print_all_byte((void *)&d3, sizeof(d3))) {
printf("printf double success!\n");
}
if(sizeof(arr1) == print_all_byte((void *)arr1, sizeof(arr1))) {
printf("printf array success!\n");
}
return 0;
}