指针的最好理解

 指针和地址区别:
   比如int类型在32位系统占用4个字节,那么int a=10; a的首地址就是地址
   int *p=&a;
   int *p表示在内存中声明4个字节的指针类型
   p=&a  表示把a的首地址保存到指针p的内存中
   *p: 获取指针p内存内存中保存地址指向的内存


  //交换2个数据用指针实现
  // a和b没有被交换,交换的是a1和b1的地址
int main(){
 int a=1;
 int b=2;
 int *a1= &a;
 int *b1= &b;
 int *temp;
 temp= a1;
 a1=b1;
 b1=temp;

 printf("%d====%d\n",*a1,*b1);

  return 0;
}
 

发布了141 篇原创文章 · 获赞 51 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/dreams_deng/article/details/91329284