Comparator is a circuit that compare two voltages. When one voltage is higher than the other, the output of comparator is in one state, either high or low. If the input conditions are reversed, output of the comparator switches to the other state.
Operational Amplifiers such as LM741, CA3140, CA 3130, TL0 71 etc can be used as voltage comparators. Op Amp has a differential input. One is Inverting input and the other is Non Inverting input. If the voltage is higher in the Non inverting input than Inverting input, output of the comparator turn high. If the voltage in the Inverting input is higher than the Non Inverting input, output of the comparator remains low. Sometimes, the Op Amp latch up and output remains same even when the voltage in the input changes. This usually happens when the op amp is driven hard.
Usually a potential divider is used to fix a reference voltage to one input, say Inverting input. So the signal to the Non inverting input is a variable one. If two equal value resistors are used as potential divider ,it gives half supply voltage as reference voltage to one input. For example if two 10K resistors are used in 12 V, the reference voltage will be 6V.