Home > Article > Backend Development > In C language, what is the register storage class?
There are four storage classes in the C programming language, which are:
The keyword is register.
The value of a register variable is stored in the CPU's register, not in memory, as ordinary variables are stored in memory.
Register is a temporary storage unit in the CPU.
They allow register variables to have faster access times than ordinary variables.
The following is the register storage class of the C program:
Demonstration
#include<stdio.h> main ( ){ register int i; for (i=1; i<=5; i++) printf ("%d ",i); }
The output is stated below −
1 2 3 4 5
Consider another C program that uses the register storage class−
Online demonstration
#include<stdio.h> int main(){ register int a; printf("%d",a); //prints default value of a =0 }
The output is stated below −
0
The following is the third C program for static storage class−
#include<stdio.h> int main(){ register int i = 10; int *p; //int *p = &i; //error occurred ,here we are trying to request address of register variable printf("Value of i: %d", *p); printf("Address of i: %u", p); }
The output is stated below −
Error:add of reg var?
The above is the detailed content of In C language, what is the register storage class?. For more information, please follow other related articles on the PHP Chinese website!