Register Storage Class

The feature of a variable defined to be of register storage class are:
-The variable is stored in CPU registers
-The initial default value is unpredictable i.e. garbage
-The scope of the variable is local to the block in which it is defined.
-The life of the variable in only till the control remains within the block in which the variable is defined.
The variable stored in CPU register are accessed much faster than those stored in memory. Therefore we can tell the compiler to store the frequently

accessed variables to be kept in register instead of memory. The storage class of a variable can be declared registered as fallows:
register int count;
Example:
A small program to declare count to be of type register could be:
main()
{
register int count;
or(count=1;count<=10;count++)
printf("\n%d",count);
}

No comments:

Post a Comment