C++中指针运算
1,指针可以和数字运算,指针+-整数,如,
int num[] = {1,2,3,4,5,6,7,8};
int *p = num;
p++;
p--;
p = p + 3;
p = p -3;
数字大小是数字*指针所指向类型的大小;
2,指针与指针减法运算,指针—指针,如:
int num[] = {1,2,3,4,5,6,7,8};
int *p = num;
int *q = &num[4];
则 q - p = 4;
又比如:在int数组中,指针p为2004,指针q为2024,则q - p = (2024-2004)/4 = 5;
3,指针可以进行关系运算:>、<、>=、<=
4,指针可以赋值