1 #pragma region 指针++,指针内存储的地址增加m位,m根据存储内容的所占字节数的大小决定 2 3 //这里通过一个顺序表来说明这一关系 4 using namespace std; 5 typedef int Status; 6 typedef int ElemType; 7 constexpr auto MAXSIZE = 100;// 最大长度; 8 typedef struct SqList { 9 ElemType *elem;//基地址10 int length;//实际长度11 }SqList;12 13 Status InitLsit_Sq(SqList &L) { //构造一个空的顺序表;&表示可以双向传递,实参把值传给形参,形实合一14 L.elem = new ElemType[MAXSIZE];//为顺序表分配空间;new申请MAXSIZE个ElemType类型的空间15 if (!L.elem) exit(OVERFLOW);//存储空间分配失败16 L.length = 0;//空表长度为017 return 1;18 }19 20 Status ListInsert_Sq(SqList &L, int i, ElemType e) { //有返回值21 if (i<1 || i>L.length + 1) return 0;//判断插入位置是否合法22 if (L.length == MAXSIZE) return 0;//判断存储空间是否已满23 for (int j = L.length; j >= i - 1; j--) { //n到i元素向后移动24 L.elem[j + 1] = L.elem[j];25 }26 L.elem[i - 1] = e;//e放置第i个位置27 ++L.length;//表长+128 return 0;29 }30 31 //根据元素内容e获取元素位置i32 int LocateElem(SqList L, ElemType e) {33 //查找不影响线性表长度和内容,实参内容值已被用户给出34 for (int i = 0; i < L.length; i++)35 if (L.elem[i] == e) return i + 1;36 return 0;//当for语句表达式为假||if表达式为假时执行return 037 }38 #pragma endregion39 40 int main()41 {42 SqList B;//B为创建顺序表的名称43 InitLsit_Sq(B);44 //顺序表B的值依次为2、3、445 ListInsert_Sq(B, 1, 2);46 ListInsert_Sq(B, 2, 3);47 ListInsert_Sq(B, 3, 4);48 int *p1 = &(B.elem[0]);49 int *p2 = &(B.elem[1]);50 int *p3 = &(B.elem[2]);51 int *p4 = p1++;//先赋值给p4,然后作p1++52 printf("%0x, %0x, %d, %d\n", p1, &(B.elem[0]), *p1, (B.elem[0]));53 printf("%0x, %0x, %d, %d\n", p2, &(B.elem[1]), *p2, (B.elem[1]));54 printf("%0x, %0x, %d, %d\n", p3, &(B.elem[2]), *p3, (B.elem[2]));55 printf("%0x, %0x, %d, %d\n", p4, &(B.elem[0]), *p4, (B.elem[0]));56 }