C语言指针用法详解(二) 指针的算术运算
例题1: Question : char a[20]; int *ptr = (int * )a; ptr++ Practice : Reason : #include <bits/stdc++.h> using namespace std; int main() { char a[20]; int *ptr = (int * )a;/// 强制类型转换不会改变a的类型 /*** ** 吾日三醒指针:指针的类型,指针指向的类型,指针指向哪里 ** ptr 的类型是 int* , 指向的类型是 int , 指向整形变量 a ***/ cout<<" befor : " << ptr<<endl; ptr++; cout<< " sizeof (ptr) "<< sizeof(ptr)<<endl; /*** ** ptr 类型是指针,指针的自增,当然是增加自身的大小了 ** sizeof(ptr) 为4, ptr 增加4 ***/ cout<<" after : "<<ptr<<endl; } 例题2: Question : int arr[20] = {0}; int *ptr = arr; for (int i=0; i<20; i++) { (*ptr)++; ptr++; } Practice : Reason : #include <bits/stdc++.h> using