Register storage class
the syntax is
Ex:
Some compiler will alllow only int and char datatype while the others will allow all the datatypes.If the number of variables exceed the limit of CPU register then the variable is not stored in CPU register and is stored in memory(RAM)
The main advantage of using register storage class is the fast access of the register variable when compared to the normal variable.The difference is best seen when we declare a looping variable or counter using register storage class..
ex:
Now run this program and note the delay and then modify the above program as
and note the delay.Time gap will increases as the limit increases.
Now the biggest disadvantage of register variables is they have no memory locations or addess.That means we cannot use '&' when we are working with register variables
ex:
consider the following program..
if you compile the above program,compiler will issue an error.In order to solve this drawback you have to use a dummy variable.i.e,
the output of the above program is
coming next:extern
If we use register storage class then the variable is stored in the CPU registers.Register access is very fast.It is best used for looping variables or counters.
the syntax is
Code:
register datatype variable
Code:
register int a=5;
Some compiler will alllow only int and char datatype while the others will allow all the datatypes.If the number of variables exceed the limit of CPU register then the variable is not stored in CPU register and is stored in memory(RAM)
The main advantage of using register storage class is the fast access of the register variable when compared to the normal variable.The difference is best seen when we declare a looping variable or counter using register storage class..
ex:
Code:
#include<stdio.h>
main()
{
register long i;
for(i=0;i<900000000;i++);
printf("Over\n");
}
Now run this program and note the delay and then modify the above program as
Code:
long i;
and note the delay.Time gap will increases as the limit increases.
Now the biggest disadvantage of register variables is they have no memory locations or addess.That means we cannot use '&' when we are working with register variables
ex:
consider the following program..
Code:
#include<stdio.h>
main()
{
register int a=8;
printf("a= %d\n",a);
scanf("%d",&a);
printf("a=%d\n",a);
}
if you compile the above program,compiler will issue an error.In order to solve this drawback you have to use a dummy variable.i.e,
Code:
#include<stdio.h>
main()
{
register int a=8;
int b;
printf("a= %d\n",a);
scanf("%d",&b);
a=b;
printf("a=%d\n",a);
}
the output of the above program is
Code:
a=8
10
a=10
coming next:extern
Last edited: