Re: [C]关于指针的问题

  • From: "Tang Martin" <codemastor@xxxxxxxxx>
  • To: ghostunix@xxxxxxxxxxxxx
  • Date: Sat, 24 May 2008 11:27:12 +0800

呵呵 指针的研究方法:

首先了解小端结束(Little-endian)和大端结束(Big-endian)的概念,然后在不同结束方式的处理器上编写如下C代码:

int main()
{
  unsigned data = 0x89abcdef;
  unsigned char *pchar = (unsigned char*)&data;
  unsigned short *pshort = (unsigned short*)&data;
  unsigned int *pint = (unsigned int*)&data;

  // print out results:
  printf("uchar: %x\n", *pchar);
  printf("ushort: %x\n", *pshort);
  printf("uint: %x\n", *pint);
  return 0;
}

Other related posts: