1

I have always read that in order to modify any variable inside a function in C, you must pass a pointer to that variable.

If I want to delete a particular element in a linked list, and I do something like:

int DeleteElement(element **head, element *deleteMe)
{
  free(deleteMe);
  return 1;
}

Why am I able to free that deleteMe and that gets reflected outside the DeleteElement function? Isn't the deleteMe another thing inside the function?

Thanks

4

2 に答える 2

0

pointer には何も書き込んでいませんdeleteMe。これを (読み取り専用の方法で) 使用して、解放するオブジェクト (それが指しているオブジェクト) を決定しています。

于 2013-01-20T14:33:50.297 に答える
0

アドレスへのポインターを渡します(そのポインターを提供するために使用する名前または変数は関係ありません)。そのアドレスのメモリ ブロックが解放されます。したがって、DeleteElement関数の「外部」でも解放されます。

于 2013-01-20T14:34:01.750 に答える