answersLogoWhite

0

What is a register variable in c programming?

Updated: 8/20/2019
User Avatar

Wiki User

8y ago

Best Answer

A register variable is a variable that we wish to allocate in a CPU register rather than in a memory address (RAM). Register variables must be less than or equal in length to the word length of a CPU register which typically limits their use to integral types and pointers. Typical uses for register variables include counters, accumulators and other regularly-accessed variables within a localised code block.

Storage classes were originally inherited from B, however only the static and extern storage classes have any meaningful purpose in C. The register storage class is largely redundant while the auto storage class is wholly redundant.

Explicitly declaring a register variable is no guarantee the variable will actually be allocated to a register, it is merely a hint to the compiler that the variable is a candidate. However, modern compilers are perfectly capable of determining which variables make good candidates without hints, so there is typically no need to explicitly declare them. If we have more good candidates than there are registers available, explicitly declaring our preferred candidates might be considered worthwhile, however it's generally better to just let the compiler decide.

Note that register variables have no memory address. If we take the address of any variable using the unary '&' operator, then that variable can no longer be considered as a register variable candidate by the compiler. If we explicitly declare a register variable and subsequently attempt to take its address, the compiler will issue a warning, yet another reason to simply let the compiler decide.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a register variable in c programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are register variables in c?

A register specifier for a variable is a compiler hint that the variable is used often and should be kept in a CPU register. The compiler will treat the variable as automatic, but it will give it preference for staying in a register between sequence points.


What is printing out and inputting variable in C programming?

input and output


What is the difference between normal variable and register variable in c?

In C/C++ when we declare a variable; e.g int var; for this variable (i.e. var) memory is being reserved in RAM (i.e out side processor). If we declare variable like that; register int var2; for this variable memory is being reserved in register of CPU (i.e. withing processor) But register variables are discouraged because processor has to work with registers..... Note: strictly speaking, storage class 'register' means: dear compiler, you might optimize this variable into register, as I won't ever request its address. But of course, it's up to you to decide.


What does increments mean in C programming?

It has nothing to do with C, it simply means: add 1 to a variable.


What are the different storage class in C programming?

Automatic, register, external, static


Difference between register variable and automatic variables?

Register variables are stored in register of microprocessor/micro-controller. The read/write access to register variable is the fastest because CPU never need any memory BUS operation to access these variable. Auto variable are stored in stack thus access are much slower. Auto variable can be converted to register by using register keyword before it. It has platform specific limitation. Register variable will work only if free registers are available to hold the variable for a function scope. In case of Microprocessor or microcontrollers having very less number of general purpose registers will never take register variable even if we declare it as register.


What is 'variable' in C programming?

It's a part of the program's data, which has a name,type and value.


Why c in and c out used in c?

In the programming language C++, cin is used to input the variable and cout is used to print a certain message or result.


What is the definition of the term C static?

The term C static is a variable within computer programming in particular C Language. When set static the variable inside a function keeps its value between invocations.


Why use static variable in programming language?

For C programming, the use of a static variable has two uses: One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in. The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.


How do you swap in c programming?

the simple way can be explained by example as: let there be two integers as : int a=10,b=5; if we want to use third variable then let third variable be int c; and sorting is done as : c=a; a=b; b=c; if it is to be done by without using third variable then : a=a+b; b=a-b; a=a-b; at last the variable is sorted.


What is a ponters in c-programming?

with the help of pointers we able to store the memory location of any variable. In c the pointer variable is use to store the memory location of any variable. The pointer variable is define as a simple variable but in pointer variable use a special "*" character at the left most side of name of pointer variable. If any variable name have * it means it is a pointer variable it hold the memory location of variable.