Search⌘ K
AI Features

Incrementing and Decrementing Numbers

Explore how to increment and decrement numbers through pseudocode, C/C++, and assembly instructions like INC and DEC. Understand their representation in GDB disassembly and how memory and registers update during these operations.

Increment and decrement numbers

In pseudocode, incrementing or decrementing the number stored in location (address) a looks very simple:

(a) + 1 -> (a)
(a) – 1 -> (a)

Increment and decrement in C and C++

In C and C++, we can increment and decrement in three different ways:

C++
# Increment
a = a + 1;
++a;
a++;
# Decrement
b = b – 1;
--b;
b--;

Increment and decrement in assembly language

In assembly language, we use instructions INC and DEC and write:

Assembly (GAS x86)
incl a
inc %eax
decl a
dec %eax

We use incl when we ...