The physics are pretty simple: the golf ball will go straight up if you hit the ball up at all. The more launch the ball gets, the higher the marshmallow will go.
It's an easy trick too if you can balance one golf ball on top of the other: hit the bottom one, catch the top one in your pocket or something. We used to goof around doing that all the time.
Or, for bonus points, hit the bottom ball, and then hit the top one as it falls down out of the air!