Register variables in C

A register variable is used because it makes the programming faster on a variable. It is kept in the CPU and memory access is not required to modify its value. Example: Function to compute b to the power of a:

int power(register int a, register int b)


register int temp;

temp = 1;

for(; b; b–) temp = temp * a;

return temp;


Here a, b and temp are declared as register variables to speed up the computation.

Leave a Reply