關(guān)于C++指針的類型及強制類型轉(zhuǎn)換
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[]={1,2};
char arr2[]={255,255,255,255, 255,255,255,254};
void *p3=arr1;
int *p1=(int*)p3;//這里是指針的強制類型轉(zhuǎn)換,即把萬能指針p3抓換成int指針p1
int *p2=(int*)arr2;
*p1=*p2;
printf("%x",*p1);
char *p5=arr2;
int a=*((int*)p5); //這里是把指針強制轉(zhuǎn)換后再通過指針把數(shù)值傳給int變量a
printf("%x",a);
return 0;
}
評論