#include <stdio.h>
struct mychar {
char value;
struct mychar *nextPtr;
};
typedef struct mychar Mychar;
void insert(Mychar **, char );
int main(){
Mychar *startPtr = NULL; // line 13
insert(&startPtr, 'b');
}
void insert(Mychar **sPtr, char myvalue){
if (**sPtr == NULL){ // if I put double ** it doesn't work. it works only with one *
// do stuff
}
I got this error:
liste_collegate.c:13:13: error: invalid operands to binary expression ('Mychar' (aka 'struct mychar') and 'void *')
if (**sPtr == NULL){
~~~~~~ ^ ~~~~
I really don't get why if I initialize startPtr at line 13 with Mychar *startPtr = NULL;
and then I pass the address of that pointer to insert
function, 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 NULL
? 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...
Why doesn't it work?
Of course I know that there must be something wrong, just I don't know why.