What are register variables?

1 reply [Last post]
dhanunjaya
Offline
Last seen: 9 years 33 weeks ago
Joined: 2009-04-26
bOt Points: 153

What are register variables? What are the advantage of using register variables?

bOtskOOl
Offline
Last seen: 9 years 31 weeks ago
Joined: 2009-02-21
bOt Points: 3500
Re: What are register variables?

Register variables are a special case of automatic variables. Automatic variables are allocated storage in the memory of the computer; however, for most computers, accessing data in memory is considerably slower than processing in the CPU. These computers often have small amounts of storage within the CPU itself where data can be stored and accessed quickly. These storage cells are called registers.

 

Normally, the compiler determines what data is to be stored in the registers of the CPU at what times. However, the C language provides the storage class register so that the programmer can suggest to the compiler that particular automatic variables should be allocated to CPU registers, if possible. Thus, register variables provide a certain control over efficiency of program execution. Variables which are used repeatedly or whose access times are critical, may be declared to be of storage class register. Example:-



void main()

{

register int a=0;

/*rest of the program*/

}