只有当我一个*时,双指针**和常量之间的比较才有效

#include <stdio.h>


struct mychar {
    char value;
    struct mychar *nextPtr;
};

typedef struct mychar Mychar;


void insert(Mychar **, char );

int main(){
    Mychar *startPtr = 3;    // line 13

    insert(&startPtr, 'b');

}

void insert(Mychar **sPtr, char myvalue){

    if (**sPtr == 3){    // if I put double ** it doesn't work. it works only with one *
        // do stuff
    }

I really don't get why if I initialize startPtr at line 13 with Mychar *startPtr = 3; and then I pass the address of that pointer to insertfunction, I can't get the value if I put two ** but it works only if I put only one *.

Shouldn't I dereferenciate two times in order to reach value 3? I mean, if I am passing an address of a pointer to a function, that function will need to derefernciate one time to reach the value of the address inside the first pointer, and then another time to reach the real value in that address...

为什么不起作用?

我当然知道一定有问题,只是我不知道为什么。

评论