Register Storage Class in C

o	Keyword : register
o	Storage Location : CPU Register
o	Initial Value : Garbage
o	Life : Local to the block in which variable is 
        declared.
o	Scope : Local to the block.

Syntax :

	register [data_type] [variable_name];

Example :

	register int a;

When the calculations are done in CPU, then the value of variables are transferred from main memory to CPU. Calculations are done and the final result is sent back to main memory. This leads to slowing down of processes.

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.

It is not applicable for arrays, structures or pointers.

It cannot not used with static or external storage class.

Unary and address of (&) cannot be used with these variables as explicitly or implicitly.

Program :

/*  Program to demonstrate register storage class.
Creation Date : 09 Nov 2010 11:50:55 PM
Author : www.technoexam.com [Technowell, Sangli] */

#include <stdio.h>
#include <conio.h>

int main(void)
{
	register int i=10;
	clrscr();
	{
		register int i=20;
		printf("\n\t %d",i);
	}
	printf("\n\n\t %d",i);
	getch();
	return 0;
}

Output :

	20

	10_

Leave A Comment

Your email address will not be published. Required fields are marked *