When understanding how primitive operators such as +
, -
, *
and /
are implemented in C, I found the following snippet from an
To be pedantic, the C specification does not specify how addition is implemented.
But to be realistic, the +
operator on integer types smaller than or equal to the word size of your CPU get translated directly into an addition instruction for the CPU, and larger integer types get translated into multiple addition instructions with some extra bits to handle overflow.
The CPU internally uses logic circuits to implement the addition, and does not use loops, bitshifts, or anything that has a close resemblance to how C works.