Pointer To Pointer

Some hold that pointers in a language like C are dangerous and hard to master. Both maybe true, but so are scalpels. Since you are reading this, you know that pointer practice makes pointer perfect. The same goes for pointers to pointers. I remember vividly when I first saw some elegant code that used a pointer to a pointer (I was working on Amoeba). It was a coding changing event. Before I would write like:
Picture 2
After I would write:
Picture 3
I’ve even used that last bit of code in job interviews. If some self proclaimed hardcore C coder could not explain those lines of code I would know they were no experts. Now that this trick is out of the bag, I will have to use an other one, next time we meet.


  1. John Sinteur says:

    Which version is easier to maintain?

  2. coder says:

    Well, that depends, if your dime has dropped on pointers to pointers, it is by far less error prone because the execution path has no branches. With the other code, you have to get all the execution paths right. For example if you type: “root->data < number" in the first if block, it might be hard to spot, a function test might even miss it.

Leave a Reply