The documentation should specify more explicitly is the return value for this function:
https://root.cern.ch/doc/master/classTH1.html#a32f93abdded52db93b4eec74e817ee7d
I’m pretty sure the return value is the same pointer as the 2nd argument, when passed a TH1*, or the pointer to the TH1* created when that argument is left out, but the documentation doesn’t say.
Jean-François