Tuesday, March 22, 2011

Program for Register variables with Explanation


Program

#include <stdio.h>
main()
{
    register int i = 0;    \\ A

    for( i=0;i<2;i++)
    {
        printf("value of i is %d\n",i);
    }
}

Explanation

  1. Here the register allocation directive is given for variable i. During execution, i will be allocated a register if it is available; otherwise, i will receive normal memory allocations.
  2. You can use a register directive only for variables of the automatic storage class, not for global variables.
  3. Generally, you can use register storage for int or char data types.

No comments:

Post a Comment