A register variable is stored in one of the microprocessor's registers, rather than in random-access memory (RAM). This speeds up access to the variable.
A conventional variable can become a register variable in either of the following ways:
The variable is declared as a register variable. If a register is free, the compiler stores the variable there.
The compiler stores a frequently used variable (such as a loop variable) in a register during optimization to speed up execution.
Register variables can cause problems during debugging. As with local variables, they are visible only within the function where they are defined. In addition, a register variable may not always be displayed with its current value.
Usually, it is a good idea to turn off all optimization and to avoid declaring register variables until the application has been fully debugged. Any side effects produced by optimization or register variables can then be easily isolated.