A ballcock or float valve is a mechanism used to fill water tanks, such as toilets. It also helps to prevent overflow and backflow. The mechanism was invented by a Mexican priest and scientist called José Antonio de Alzate y Ramírez (1737-1799). He first described the device in the 'Gaceta de Literatura Méxicana' (Mexican Literature Gazette) in 1790.

A ballcock is positioned near the top of the tank and consists of a valve connected to a hollow sealed float by a lever. The float is often ball-shaped, hence the name. The valve is connected to the incoming water supply. When the water level rises, the float rises with it, causing the lever to close the valve when it reaches a certain height.

The ballcock also responds to the drop in water level, which then refills the tank. If the float or valve fails to trigger, the water level will exceed the fill line and pour into an overflow tube and out into an outside drain. This prevents the toilet from flooding.

More Info: en.m.wikipedia.org