Please don\'t close this saying a duplicate question. I made an important change so not to confuse people, I resubmitted this much clearer codes.
One nice idiom that you can use as well is eg:
hash = (HashTablePtr) malloc(sizeof(*hash));
By not hard-coding any types in the allocation, the possibility of mixing things up is greatly reduced.
Note that 'hash' is not actually dereferenced here - sizeof() is always evaluated at compile time, so the compiler just figures out what type *hash /would/ have, and gets the size of that.