3

以下はサンプルコードであり、動作するものではありません。Cのポインターの*headとの違いを知りたいだけです。(*head)

int  insert(struct node **head, int data) {

      if(*head == NULL) {
        *head = malloc(sizeof(struct node));
        // what is the difference between (*head)->next and *head->next ?
        (*head)->next = NULL;
        (*head)->data = data;
    }
4

5 に答える 5

2

a+b と (a+b) には違いはありませんが、a+b*c と (a+b)*c には大きな違いがあります。*head や (*head) ... (*head)->next も同様で、*head の値をポインタとして、その次のフィールドにアクセスします。*head->next は *(head->next) ... と同等です。head は構造体ノードへのポインターではないため、コンテキストでは無効です。

于 2013-06-06T11:52:59.600 に答える