register Variables in C

By: Grenfel Printer Friendly Format    

A register declaration advises the compiler that the variable in question will be heavily used. The idea is that register variables are to be placed in machine registers, which may result in smaller and faster programs. But compilers are free to ignore the advice.

The register declaration looks like

   register int  x;
   register char c;
and so on. The register declaration can only be applied to automatic variables and to the formal parameters of a function. In this later case, it looks like
   f(register unsigned m, register long n)
       register int i;
In practice, there are restrictions on register variables, reflecting the realities of underlying hardware. Only a few variables in each function may be kept in registers, and only certain types are allowed. Excess register declarations are harmless, however, since the word register is ignored for excess or disallowed declarations. And it is not possible to take the address of a register variable, regardless of whether the variable is actually placed in a register. The specific restrictions on number and types of register variables vary from machine to machine.

Most Viewed Articles (in C )

Latest Articles (in C)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. Can you provide some more specific application of
View Tutorial          By: Rushikesh at 2012-01-15 18:23:36

2. SitsCistmix
View Tutorial          By: SitsCistmix at 2013-05-19 21:23:45

3. EruroErardDot
View Tutorial          By: EruroErardDot at 2015-04-02 12:06:13

4. RichardJal
View Tutorial          By: RichardJal at 2015-08-27 04:26:05

5. Lyrica Ancef
View Tutorial          By: Lyrica AncefSP at 2016-11-20 05:05:49

6. If i give register int a[100], what will happen? S
View Tutorial          By: ramkumar at 2017-01-28 09:41:23

7. WayneNub
View Tutorial          By: WayneNub at 2017-04-27 22:10:43

8. abookzrar
View Tutorial          By: abookzrar at 2017-05-16 03:37:52