Saturday, January 21, 2012

Pointers to Pointers

Yes you can have Pointers to Pointers in C. Since everything is passed by copy unless specified than you need to pass a pointer to a pointer for things like linked list

void foo(List **l){
*l = (*l)->next;
}

List L;
List *lP = &L;
foo(&lP);

No comments:

Post a Comment