How the pull-up resistor settles the logic level?
For example, If i were to remove the pull-up resistor from the circuit above, and the switch is open, still the voltage of the gate is pulled up the level of Vin.


There are two ways of interpreting this sentence, both of which lead to problems in the circuit.

If we replace the resistor with an open, the input will be floating when the switch is open. You do not want floating inputs on CMOS inputs as that can lead to increased power consumption and possibly damage the input stage.

If we replace the resistor with a short, the input will indeed be pulled high when the switch is open. But if the switch is closed then you will short out your supply which is a Very, Very Bad Thing.

In both cases the solution is to have a resistor to the positive supply and a switch to ground, or vice versa depending on what you want the default input logic level to be.