It's getting the order of operations mixed up, adding an offset to a pointer then dereferencing it instead of dereferencing it then adding an offset. (*var)[j] instead of *var[j]
Yes, local variables like that and pointers to them don't remain valid after the function call they exist inside returns. That it works at all is simply a coincidence. Make a few more function...