What is register variable in C language ?


Posted On: Feb 22, 2018


C language allows the use of the prefix register in primitive variable declarations. Such variables are called register variables and are stored in the registers of the microprocessor. The number of variables which can be declared register are limited. If more variables are declared register variables, they are treated as auto variables. A program that uses register variables executes faster as compared to a similar program without register variables. It is possible to find out the allocation of register variables only by executing and comparing the performance with respect to the time taken by the program (perceptible in large programs). It is the responsibility of the compiler to allow register variables.

In case the compiler is unable to do so, these variables are treated as auto variables. Loop indices, accessed more frequently, can be declared as register variables. For example, index is a register variable in the program given below.

//Illustration of register variables in C language

#include <stdio.h>
#include <string.h>
int main()
  char Name[30];
  register int Index;
  printf( "Enter a string: ");
  gets( Name );
  printf( "The reverse of the string is : ");
  for( Index = strlen( Name ) - 1; Index >= 0; Index-- )
	  printf( "%c", Name[Index]);
  printf( "\n" );
  return 0;
Enter a string: Apple is Red
The reverse of the string is : deR si elppA

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    C Programming Interview Questions

    What are static variables in C ?

    C defines another class of variables called static variables. Static variables are of two types:Static variables tha..

    C Programming Interview Questions

    What is a scope resolution operator in C ?

    The scope resolution operator (::) is useful in C programming when both global and local variables have the same name,..

    C Programming Interview Questions

    What is a structure in C Language.How to initialise a structure in C?

    A structure is a composite data type declaration that defines a physically grouped list of variables to be placed under..