register

By postponing a local declaration or a formal parameter declaration to the register specifier, one gives indication to the compiler that the variable is to be placed in a register for faster computation:

register char c = 'a';
register int b = 7;
Only int’s and char’s, though, get actually to be contained in a register. For all other types of variables, objects, arrays, etc. the use of register usually translates into a non-specified implementation-dependent increase in the speed of computation. Further, notice that global register variables are not allowed. In the example below. Notice the typical use of register to increase the speed in the access to a variable controlling a loop.

Example


#include <iostream>
using namespace std;

// register int a; ERROR! Global register: illegal.

int main()
{   
     float register floatArray[2] = {0.1f, 0.2f};
     register char c = 'a';
     for(register int i = 0; i <10000; i++)
     {
           // ...
     }

}