The first is read-modify-write: it reads the current register, ORs in bit 5, and writes back, so pin 5 goes high and the other 15 pins keep their existing states. The second is a plain assignment: it writes the literal value 0x20 to the whole register, forcing pin 5 high and every other pin to 0. If those other pins were driving LEDs, relays, or chip-selects, the assignment silently switches them all off. Updating one pin among many almost always requires the |=/&= ~ read-modify-write form; the bare = is only correct when you genuinely intend to set the entire register at once (e.g. a known full-port configuration at init).
C Programming · Interview question
What's the difference between GPIOA->ODR |= (1u << 5) and GPIOA->ODR = (1u << 5)?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Bit Manipulation & Masks
Set, clear, toggle, and test individual bits without disturbing their neighbors: the read-modify-write idioms behind every GPIO and peripheral driver.