What is the purpose of a pull-up resistor in a microcontroller?
A pull-up resistor does two things:

Prevents the pin from floating
Floating CMOS inputs can result in increased power consumption, or in some cases even destruction of the device. A pull-up holds the input to a known good state.

Defaults the input to a high value
This is useful when dealing with open-drain outputs that work in a wired-OR/pull-down fashion such as interrupt lines, or even with simple buttons.


It also causes the input to source a small amount of current for detection purposes, but this usage is much less prevalent than the previous two.