void printMemByByte(int * ptr,int len);
void print32BitsByByte(int *i);
int main() {
int b=0xABCD;
cout<<"int value b:"<<endl;
printMemByByte(&b,1);
char s[] = "abc"; cout<<"array s:"<<endl;
printMemByByte((int *)s,1);
char * p3 = "123456";
cout<<"pointer p3:"<<endl;
printMemByByte((int *)p3,(int)((float)7/4+0.5));
p1 = (char * ) malloc(10);
strcpy(p1, "123456");
*(p1+10)=(char)257;//same to arrange it 1 as -256+257
*(p1+11)=(char)3;//越界不会产生编译错误,只会在运行时发生逻辑错
cout<<"pointer p1:"<<endl;
printMemByByte((int *)p1,(int)((float)10/4+0.5));
char c1 ;
cin>>c1;
return 0;
}
void print32BitsByByte(int *i){
__int8 * pByte=(__int8 *)i;
//cout<<"Addr of i :"<<hex<<(void *)pByte<<endl;
cout<<hex<<(__int8 *)pByte<<" ";
while(pByte<((__int8 *)i+sizeof(int))){
cout<<hex<<(((__int8)(*((__int8 *)pByte++)))&0xFF)<<" ";
}
cout<<endl;
}
void printMemByByte(int *ptr,int len){
int i=0;
for(;i<len;i++){
print32BitsByByte((int *)ptr++);
}
}