如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
C/C++学习笔记1:指针变量名称以p为首字符,这是程序员通常在定义指针时的一个习惯2:har*p;(int*)p把p强制转换为int型3.1:指针的问题:指针应用时最好给予定义(初始化)这样可以保证指针的指向是程序员自己能够把握的。3.2:指针的越界,这恐怕是最难查出的吧!3.3:指针的局部变量问题。局部的指针变量会被程序自动释放,若程序员引用此类指针就会出错。2007-9-14.二维指针的应用实例:#include<stdio.h>#include<string.h>voidsort(char(*client)[10]);voidmain(){inttemp;charclient[3][10];char(*pClient)[10]=NULL;for(temp=0;temp<3;temp++){gets(client[temp]);}pClient=client;sort(pClient);for(temp=0;temp<3;temp++){puts(*(pClient+temp));}}voidsort(char(*client)[10]){//冒泡算法的明了写法inttemp1,temp2;chartemp[10];for(temp1=2;temp1>0;temp1--)//控制每一步的比较次数{for(temp2=0;temp2<temp1;temp2++)//比较指针{if(strcmp(*(client+temp2),*(client+temp2+1)))//比较过程{strcpy(temp,*(client+temp2));strcpy(*(client+temp2),*(client+temp2+1));strcpy(*(client+temp2+1),temp);}}}}5.类型转换中的结构体:如p=(structstudent*)stu[0].name将p指向结构体的内部元素的地址,要进行类型转换,先转换为p的类型。6.定义在函数内部的指针结构体是不会被系统释放的。例程:猫和老鼠。voidInsert(structstudent*pHeadGet,intnumInsert){structstudent*pOne,*pTwo,*pInsert;inttemp;pTwo=pOne=pHeadGet;for(temp=0;temp<numInsert-1;temp++){pTwo=pTwo->pNext;}pOne=pTwo->pNext;printf("Pleaseintothenumberandthescore:\n");pInsert=(structstudent*)malloc(LEN);//这个在函数内部开辟的空间在函数调用后还是保留在内存scanf("%d%d",&pInsert->number,&pInsert->score);pTwo->pNext=pInsert;pInsert->pNext=pOne;}7:连接字符的错误写法:#include<stdio.h>main(){chara[]="woshilibingbing",b[]="lijiangyeshiwo";char*p1,*p2;p1=a;p2=b;//*(p1+17)=*(p2+0);//(p1+17)=p2;此处在尝试改变数组的值,这是不允许的printf("%s",p1);}8.指针中赋值和修改的一些容易错误和注意的地方#include<stdio.h>voidmain(){charamessage[]="nowisthetime";char*pmessage="nowisthetime";int*pInt={2,3,6,23};//这样的定义是不允许的*(amessage+3)='H';//*(pmessage+3)='H';不能尝试修改指针定义的字符数组printf("%s\n%s\n",amessage,pmessage);pmessage=amessage;*(pmessage+3)='h';printf("%s\n%s\n",amessage,pmessage);//从执行结果可以知道指针只是一种指向,不能达到引用并修改字符串的能力//*(pInt+3)=8;//printf("%d",pInt);}9.字符串的操作:stringDepart()//讲字符串进行分解成单个单词的形式//返回打印结果while(tempChar=GETCHAR!=EOF){if(tempChar==(‘’||‘\n’||‘\t’)){if(S