求解堆栈生长方向和大小端问题
测试代码:
#include <iostream>using std::cout;using std::endl;using std::cin;void main(){ //测试大小端// int a=0x12345678;// cout<<std::hex;// cout<<a<<endl;// unsigned char *p=(unsigned char *)(&a);// if(0x78==*p)// cout<<"bignd"<<endl;// else if(0x12==*p)// cout<<"little"; //测试地址的生长方向 unsigned char a1='a',b1='b',c1='c',d1='d'; unsigned char * pchar=NULL; pchar=&a1; cout<<(int)(&a1)<<endl; cout<<(int)(&b1)<<endl; cout<<(int)(&c1)<<endl; cout<<(int)(&d1)<<endl<<endl; while (pchar>=&d1) { cout<<*pchar<<" "<<(int)pchar<<endl; pchar--; } char *pr=new char[4]; cout<<endl; cout<<(int)pr<<endl; cout<<(int)(pr+1)<<endl; cout<<(int)(pr+2)<<endl; cout<<(int)(pr+3)<<endl<<endl; system("pause");}