ポインターの混乱に関しては、写真は常に良いです。
int * A; // create a pointer to an int named "A"
int * B; // create a pointer to an int named "B"
A = (int *)malloc( size_t somenumber ); // Allocate A some memory, now B is an
// uninitialized pointer; A is initialized,
// but just to uninitialized memory
概念的に:

B = A; // Assign B to the value of A (The uninitialized memory)

free(A);

結局のところ、何が起こっているのかを見ることができると思います。B には、割り当てられた初期化されていないメモリ チャンクである A の値が割り当てられています。これで、同じ領域を指している 2 つのポインターができました。
質問に関しては、free()
呼び出したときにわかるようにfree(A);
、A と B の両方が同じ領域を指しているままになり、プログラムには何も割り当てられていません。これが、呼び出し時にfree()
ポインターを に設定するのが良い理由NULL
です。
最初の質問に戻ります。2 つのポインターを確認したい場合==
:
int * A; // create a pointer to an int named "A"
int * B; // create a pointer to an int named "B"
A = (int *)malloc( size_t somenumber ); // Allocate A some memory, now B is an
// uninitialized pointer; A is initialized,
// but just to uninitialized memory
if(B == A){
// The pointers are pointing to the same thing!
}
if(*B == *A){
// The values these pointers are pointing to is the same!
}
更新
更新された質問に答えるには、 の定義を変更する必要がありB
ます。
int *A; // A is a pointer to an int
int **B; // B is a pointer to a pointer to an int
B = &A; // B is now pointing to A
それを説明するために:

の場合B=*A
:
int *A;
int B;
A = malloc(sizeof(int));
*A = 5;
B = *A;
これは の順守ですA
。したがって、 A が指しているものを何でも取り、それを に割り当てるだけです。B
この場合は 5