main() 

  char *sz = "0123456789"; 
  int *p = (int*)sz; 
  printf("%x\n",*++p); 
} 字符’0‘对应的十六进制是0x30
下边是我用DELPHI写的var
  Sz: PChar;
  P: PInteger;
begin
  Sz := '0123456789';
  p := Pinteger(Sz);
  Inc(P);
  ShowMessage(IntToHex(p^, 8));
end;
下边是别人解释
主要考察的目的是大端和小端的问题。 
对于intel架构的cpu,如果出现跨多个自己的数据类型,如int,long等,低地址存储数据的地位,高地址存储数据的高位。 
现在我假定: 
地址从@0开始,那么sz在内存的存储为 
@0  @1  @2  @3  @4  @5  @6  @7  @8  @9 
0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 
当你把char*强制类型转化成int*后,因为int占四个字节,那么p指向@0,并且*p占有的地址是@0@1@2@3,打印的时候 
先进行++p操作,那么p指向@4,此时*p占有的地址是@4@5@6@7,根据上面地地址存地位,高地址存高位的解释,那么 
*p应该等于0x37363534大家如果还有更好的解释可以贴出来,呵呵 

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Sz: PAnsiChar;
      P: PInteger;
      c : pByteArray;
      d : integer;
    begin
      Sz := '0123456789';
      p := Pinteger(Sz);
      Inc(P);
      c := PByteArray(P);
      showMessage(inttostr(ord('4')));
      showMessage(format('0=%d,1=%d,2=%d,3=%d'+#13#10+'0=%x,1=%x,2=%x,3=%x',[c[0],c[1],c[2],c[3],c[0],c[1],c[2],c[3]  ]));
      ShowMessage(inttoHex(p^,8));
    end;
      

  2.   

    現存的DELPHI版本下,  Sz : PAnsiChar  比較合適你的數據解釋,呵呵
      

  3.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      Sz: PChar;
      P: PInteger;
      c : pByteArray;
      d : integer;
    begin
      Sz := '0123456789';
      p := Pinteger(Sz);
      Inc(P);
      c := PByteArray(P);
      showMessage(format('0=%d,1=%d,2=%d,3=%d'+#13#10+'0=%x,1=%x,2=%x,3=%x',[c[0],c[1],c[2],c[3],c[0],c[1],c[2],c[3]  ])); // ShowMessage(inttoHex(p^,8));
     d := 1234;
     c := pByteArray(@d);
     showMessage(format('16進制值 = %x'+#13#10+'十進制值 = %d'+#13#10+'0=%d,1=%d,2=%d,3=%d'+#13#10+'0=%x,1=%x,2=%x,3=%x',[d,d,c[0],c[1],c[2],c[3],c[0],c[1],c[2],c[3]  ]));end;這樣就更加清晰了。呵呵。
      

  4.   

    我有疑问
    @0  @1  @2  @3  @4  @5  @6  @7  @8  @9 
    0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 
    当你把char*强制类型转化成int*后,因为int占四个字节,那么p指向@0,并且*p占有的地址是@0@1@2@3,打印的时候 
    先进行++p操作,那么p指向@4 为什么是@4 而不是@1
    ++p只是把p所保存的地址的值加1,为什么会跳到@4,地址加1他应该不会去区分整型而去加4吧
    所以应该是 0x31 0x32 0x33 0x34 值我就不算了
      

  5.   

    你把 
      P: PByte;  這樣就會是你要的。
      

  6.   

    If X is a pointer type, it increments X by N times the size of the type pointed to. Thus, given type
      PMyType = ^TMyType;
    and var
      P: PMyType;
    the statement Inc(P) increments P by SizeOf(TMyType). 
    看幫助說的就明白了。對於指針是如何處理。
      

  7.   

    我也觉得8楼说的对,++p只是把p所保存的地址的值加1,很明显是0x31啊
      

  8.   

    没有更好的了, 如果是moto芯片, 那就是34353637了, 这个面试题还是有点意思的
      

  9.   

    If X is a pointer type, it increments X by N times the size of the type pointed to. Thus, given type 
      PMyType = ^TMyType; 
    and var 
      P: PMyType; 
    the statement Inc(P) increments P by SizeOf(TMyType). 
      

  10.   


    hehe p已经是指向int的指针了 所以地址加4嘛
      

  11.   

    var
      Sz: PChar;
      P: PInteger;
    begin
      Sz := '0123456789';
      p := Pinteger(Sz);
      Inc(P);
      ShowMessage(IntToHex(p^, 8));
    end;
      

  12.   

    这个p指向的是int类型,指针+1操作是和数据类型有关的
      

  13.   

    应该先说明 int 是按16位还是32位