A comparator is an electrical component that compares two input voltages or currents and outputs a digital or binary signal, indicating which input is larger. If the input V+ is greater than input V-, then the output would be a logic one or high voltage. If the input V+ is less than V- the output voltage is a logic low, or binary zero.
A comparator is essentially a type of high gain differential amplifier comparing two inputs and generating an output based on what the values of the inputs are, thus being called a comparator. Due to the high gain of the amplifier, if the V+ input is larger than the V- input, the amplifier saturates or reaches its maximum possible output voltage.
Comparators can be created out of a general-purpose operational amplifier. However, a specifically designed comparator will be faster and perform better than a general-purpose op-amp configured as a comparator.
A comparator can suffer from oscillations if there is noise present on the two input terminals. This would cause the output to be unstable and continuously oscillate, or switch, even though the input voltages are quite small. To overcome this issue, a small hysteresis of a few millivolts can be implemented to limit the sensitivity to input noise.
Comparators are commonly used to interface with digital logic circuits because of their binary outputs and are building blocks of most analog to digital converters (ADC).