欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c指针学习

程序员文章站 2022-10-05 07:54:55
#include void main() { int a1=10; int a2=11; int * pa1, * pa2; pa1 = &a1; pa2 = &a2; printf("a1=%d \pa1:%p\n",a1,pa1); printf("a2=%d \pa2:%p ......

#include <stdio.h>

void main()

{


int a1=10;
int a2=11;
int * pa1, * pa2;
pa1 = &a1;
pa2 = &a2;

printf("a1=%d \pa1:%p\n",a1,pa1);
printf("a2=%d \pa2:%p\n",a2,pa2);

*pa1=*pa2;

printf("赋值后\n");

printf("a1=%d\ pa1:%p\n",a1, pa1);
printf("a2=%d\ pa2:%p\n",a2, pa2);

//*pa1=*pa2和a1=a2操作相同

//

pa2=pa1;//把pa1的指针地址复制给了pa2
printf("a1=%d\ pa1:%p\n",a1, pa1);
printf("a2=%d\ pa2:%p\n",a2, pa2);
//指针地址复制,把pa1的指针地址复制给了pa2后现在指针pa1和pa2都指向变量 a1

return 0;
}