What is the purpose of "register" keyword? It is used to make the computation faster.
The register keyword tells the compiler to store the variable onto the CPU register if space on the register is available. However, this is a very old technique. Today's processors are smart enough to assign the registers themselves and hence using the register keyword can actually slowdown the operations if the usage is incorrect.
The keyword ‘register’ instructs the compiler to persist the variable that is being declared , in a CPU register.
Ex: register int number;
The persistence of register variables in CPU register is to optimize the access. Even the optimization is turned off; the register variables are forced to store in CPU register.
|