how does this program work exactly to get the output?