#include
#include
//unsigned char恰好占用一字节,可以作为一个字节指针
typedef unsigned char *byte_pointer;
//若机器是小端机,则需要倒转着看.大端机顺着看即可
void show_bytes(byte_pointer start,size_t l)
{
size_t i;
for( i = 0; i < l; ++i)
printf("%.2x ",start[i]); //start[i]由于数组的封装相当于*(start+i)
puts("");
}
void show_int(int x)
{
show_bytes((byte_pointer)&x,sizeof(int));
}
void show_float(float x)
{
show_bytes((byte_pointer)&x,sizeof(float));
}
//展示的是指针的值,不是指针地址上存储的值,指针本身也是一个变量也有值
void show_pointer(void *x)
{
show_bytes((byte_pointer)&x,sizeof(void *));
}
void test_show_val(int val)
{
float fval = (float)val;
int *p = &val;
show_int(val);
show_float(fval);
show_pointer(p);
}
int main()
{
test_show_val(12345)
; return 0;
}