@Viraam_Rao i think i got it. See, let's break the circuit like this! The mistake sir did was he assumed C is connected to earth. C is connected to a battery but not earthed.
Now, we can see that upper and lower parts are two individual NOT gates that combine to give NAND.
Read the operation of NOT gate below, it will be Clear. If any or both of A and B is O then no current will flow through base collector or base enitter and C will be at 5 V due to battery at the top. If both are 1 then current will flow and there will be potential drop of 5V at Rc which will be opposite and equal to that of battery so C will be at 0V.