#include "stdafx.h"
typedef struct list
{
int *elem;
int len;
}Sqlist;
int _tmain(int argc, _TCHAR* argv[])
{
Sqlist qlist;
int a[4] = {0,5,8,6};
qlist.elem = a;
/*qlist.elem = qlist.elem + 2;
int *p;
p = qlist.elem;
p = qlist.elem + 4;*/
//qlist.elem = &qlist.elem[1];
int *p = &a[1];
++p;
int mm = 44;
int *kk = &mm;
*kk = qlist.elem[1]; // 地址值赋值
//++kk;// 操作错误,指针只有一个元素下标,通过元素下标++ 是指向错误地址的
++*kk; //修改指向kk的地址 + 1
int *uu;
uu = &qlist.elem[2]; //对指针变量的uu赋值,使指针指向elem 下标为 2 -1 的地址
*uu = *(uu+1);
const int *xx = &a[2];
//xx = &a[2];
++xx; //可以对指针变量做修改
//*xx = 0; //不能对地址做修改
int *const hh = &a[3];
//--hh;// 不可以对指针变量做修改
--*hh; //可以对指向a[3]的值做修改
int value = 1024;
int *q = &value;
return 0;
}
昨天在看数据结构的时候,遇到 &a[i-1] 这样一个引用操作,把他直接赋给了一个int *p; p = &a[i-1]; 这个当时非常不理解,今天有时间就对这个研究了下,对指针的操作就是解引用
,int *p = &a[i-1]; 因a[i-1]是个int 类型的,使用&就把int 的变量变成了int * 类型。就是a[i-1] 的下标i 赋给了p. 所以指针的问题也基本理解了。
指针的初始化: char *pp = new char[255]; 释放内存: delete [] pp;