C register Keyword
Example
Create a register variable:
register int myNum = 15;
// int* ptr = &myNum; // Error, because myNum is a register variable
printf("%d", myNum);
Definition and Usage
The register keyword suggests that a local variable should be stored in a CPU register (a very small and fast memory inside the processor), for faster access.
You cannot get the memory address of a register variable with the & operator. The compiler gives an error if you try.
Modern compilers choose which variables to keep in registers by themselves, so the keyword is rarely used today.
Related Pages
Read more about register in our C Storage Classes Tutorial.