Register Variables

Besides three storage class specifications namely, Automatic, External and Static, there is a register storage class. Registers are special storage areas within a computer’s CPU. All the arithmetic and logical operations are carried out with these registers.

For the same program, the execution time can be reduced if certain values can be stored in registers rather than memory. These programs are smaller in size (as few instructions are required) and few data transfers are required. The reduction is there in machine code and not in source code. They are declared by the proceeding declaration by register reserved word as follows:

register int m;

Points to remember:

• These variables are stored in registers of computers. If the registers are not available they are put in memory.
• Usually, 2 or 3 register variables are there in the program.
• The scope is the same as an automatic variable, local to a function in which they are declared.
• Address operator ‘&’ cannot be applied to a register variable.
• If the register is not available the variable is thought to be like the automatic variable.
• Usually associated integer variable but with other types, it is allowed having the same size (short or unsigned).
• Can be formal arguments in functions.
• Pointers to register variables are not allowed.
• These variables can be used for loop indices also to increase efficiency.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
?>