Register: Storage Classes

Estudies4you
Register:

Data in the machine language version of a program is normally loaded into registers for calculations and other processing. As the register memory is very limited, the compiler may ignore register declarations.

Example:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
register int c=1;
clrscr();
printf(“Enter first number\n”);
scanf(“%d”,&a);
printf(“Enter second number\n”);
scanf(“%d”,&b);
c=a+b;
printf(“the sum of %d and %d is %d”,a,b,c);
getch();
return 0;
}


OUTPUT:
Enter first number
10
Enter second number
20
The sum of 10 and 20 is 30


In the above program, the declaration register in c=1; suggest that the integer variable ‘c’ be replaced in one of the computers registers and initialized to 1:
Keyword register cannot be used with global variables as the register memory will be held up during the entire program execution.



To Top