/*
**test18.cpp : Defines the entry point for the console application.
**系统winXP SP3 32位.
**关于指针2
*/
#include "stdafx.h"
#include "iostream.h"
int main(int argc, char* argv[])
{
int* piNum = new int[100];
printf("sizeof(int) = %d\n",sizeof(int)); //4
cout<<"value piNum is: "<<(unsigned int)piNum<
cout<<"value piNum is: "<
cout<<"address piNum is: "<<&piNum<<endl; //0x0012FF7C
piNum += 50; //这里编译器写为piNum += 50 * sizeof(int),这里是将其后面指向4*50个位置
cout<<"value piNum is: "<<(unsigned int)piNum<
cout<<"value piNum is: "<
cout<<"address piNum is: "<<&piNum<<endl; //0x0012FF7C
piNum++; //即为piNum = piNum + 1
cout<<"value piNum is: "<<(unsigned int)piNum<
cout<<"value piNum is: "<
cout<<"address piNum is: "<<&piNum<<endl; //0x0012FF7C
return 0;
}
Tips1:编译器会把指针解释为unsigned int类型
Tips2:指针的++或--即为指向其序列的前一个或后一个元素,与指针本身加减某个具体数字一样的道理。