书中解释道:
ptr = &a /* set ptr to point to a */
*ptr = a /* '*' on left:set what ptr points to */
他们在我看来是一样的,不是吗?
不,第一个更改指针(它现在指向a)。第二个改变了指针指向的东西。
考虑:
int a = 5;
int b = 6;
int *ptr = &b;
if (first_version) {
    ptr = &a;
    // The value of a and b haven't changed.
    // ptr now points at a instead of b
}
else {
    *ptr = a;
    // The value of b is now 5
    // ptr still points at b
}
    不,  ptr = &a您将变量“a”的地址存储在变量“ptr”中,即类似ptr=0xef1f23.
在*ptr = a您将变量 'a' 的值存储在指针变量 '*ptr' 中,即类似*ptr=5.
嗯,不。但是为了解释类似的行为,添加到 Oli Charlesworth 的回答中:
考虑:
int a = 5;
int* ptr = new int;
if(first_version) {
  ptr = &a;
  //ptr points to 5 (using a accesses the same memory location)
} else {
  *ptr = a;
  //ptr points to 5 at a different memory location
  //if you change a now, *ptr does not change 
}
编辑:很抱歉使用new(c++ not c),但指针的东西没有改变。
两者都不相同。
如果你修改 a = 10 的值。然后再次打印 *ptr。它只会打印 5 个,而不是 10 个。
*ptr = a; //Just copies the value of a to the location where ptr is pointing.
ptr = &a; //Making the ptr to point the a
    *ptr=&aC++ 编译器会产生错误,因为你要将地址分配给 adres
 ptr=&a,这是真的,这里 ptr 像变量一样工作,&a 是 a 的地址,其中包含一些值
检查并尝试
int *ptr,a=10;
ptr=&a;output=10;
    *ptr=&a 表示我们的指针指向变量 a 的地址,而 *ptr=a 表示我们的指针指向值 a