Binary Search Tree insert while keeping track of parent for node to be added
Instead of if (n != NULL) and then indenting the whole code of function, it is better to write:
if (n == NULL) { return NULL; }
The line int cmp = (n-&gt;val &lt; x) ? -1 : (n-&gt;val &gt; x); is very hard to read. 
I suggest finding a better name to cmp - for example isGreater and changing its type to boolean.