The document was finally revised on 2021
C语言指针知识点总结
# include <>
Void g(int*p,int*q)
{
*p=1;
*q= p=q;
q=t;
return;
}
int main(void)
{
int a=3;
int b=5;
huhuan2(&a,&b);
/*huhuan2(*p,*q);是错误的
huhuan2(a,b);也是错误的*/
printf(“a=%d,b=%d\n”,a,b);
return 0;
}
a=3,b=5
Press any key to continue
互换失败
形参和实参是不同的变量,修改形参不会改变实参
指针常见错误
#include<>
Int main(void)
{
Int i=5;
Int*p;
Int*q;
P=&i;
1 2 3 4 5
-1 -2 -3 4 5 -6
1 99 22 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Press any key to continue
int main(void)
{
int a[5]={1,2,3,4,5};
int b[6]={-1,-2,-3,4,5,-6};
int c[100]={1,99,22,33};
f(a,5);//a是int*
f(b,6);
f(c,100);
return 0;
}
# include<>
//f函数可以输出任何一个一维数组的内容
void f(int * pArr, int len)
{
int i;
for(i=0,i<len,++i)
printf( “%d”,*(pArr+i) )
//*(pArr+i)等价于pArr[i] b[i] *(b+i)
printf(“\n”);
}
#include<>
Void f(int*pArr,int len)
{ pArr[2]=10;
//pArr[2]==*( pArr+2)==*(a+2)==a[2]
}
Int main(void)
{
int a[6]={1,2,3,4,5,6}
printf(“%d\n”,a[2]);
f(a,5);
printf(“%d\n”,a[2]);
//a=&a[2];//error 因为a是常量
//printf(“%#X,%#X\n”,a,&a[0]);
//a==&a[0
C语言指针知识点总结 来自淘豆网m.daumloan.com转载请标明出处.