Social Icons

9 July 2012

0 Register Storage Class

A value stored in a CPU register can always be accessed faster than the value that is stored  in computer memory. Therefore if a variable is used at many times within a program , it is better to declare its storage class as register. For example loop counter variable.Register variables occur in CPU and value of that register variable is stored in a register within that CPU. Thus, it increases the resultant speed of operations. There is no waste of time, getting variables from memory and sending it to back again.
The features of a variable defined to be of register storage class are as follows :
A register variable is declared by using keyword register.
Syntax : register type var-name;

Storage                                   :               CPU Registers
Scope                                     :                Local to the block in which variable is defined

Default Initial Value              :                Garbage Value
Lifetime                                 :               Till the control remains within the block in which   variable    is defined

Example:
#include<stdio.h>
int main()
 {
   register int i;;
    for(i=1;i<6;i++)
     printf("%d\t",i);
    return 0;
   }
Output:
1 2 3 4 5

 Limitations of register storage class :
  1.It is not applicable for arrays, structures or pointers.
  2.It cannot not used with static or external storage class.
  3.Unary and address of (&) cannot be used with these variables as explicitly or implicitly.

0 comments:

Post a Comment

Hey this is a test comment

Related Posts Plugin for WordPress, Blogger...