Register variables tell the compiler to store the variable in a CPU register instead of in memory. Frequently used variables are kept in registers, where they have faster accessibility. We can never get the addresses of these variables. Register variables are declared using the "register" keyword.
Scope - They are local.
Default value - The default initialization value is garbage.
Lifetime - Before the execution of the block in which it is defined ends.
The following is an example of a register variable in C language:
Demonstration
#include <stdio.h> int main() { register char x = 'S'; register int a = 10; auto int b = 8; printf("The value of register variable b : %c</p><p>",x); printf("The sum of auto and register variable : %d",(a+b)); return 0; }
The value of register variable b : S The sum of auto and register variable : 18
Register keyword can also be used Used with pointers. It can hold the address of a memory location. It doesn't produce any errors.
The following is an example of the register keyword in C language
Real-time demonstration
#include<stdio.h> int main() { int i = 10; register int *a = &i; printf("The value of pointer : %d", *a); getchar(); return 0; }
The value of pointer : 10
The above is the detailed content of In C language, the 'register' keyword. For more information, please follow other related articles on the PHP Chinese website!