what is the difference between static variable and register
variable?
Answer Posted / naresh lingampally
Variables defined local to a function disappear at the end
of the function scope. So when we call the function again,
storage for variables is created and
values are reinitialized.
Static variables:
So if we want the value to be extent throughout the life of
a program, we can define the local variable as "static."
Initialization is performed only at the first call and data
is retained between func calls.
REGISTER VARIABLE :
Register variables are a special case of automatic
variables. Automatic variables are allocated storage in the
memory of the computer; however, for most computers,
accessing data in memory is considerably slower than
processing in the CPU. These computers often have small
amounts of storage within the CPU itself where data can be
stored and accessed quickly. These storage cells are called
registers.
Normally, the compiler determines what data is to be stored
in the registers of the CPU at what times. However, the C
language provides the storage class register so that the
programmer can ``suggest'' to the compiler that particular
automatic variables should be allocated to CPU registers, if
possible. Thus, register variables provide a certain control
over efficiency of program execution. Variables which are
used repeatedly or whose access times are critical, may be
declared to be of storage class register.
Also these register variables are used in huge projects the
tiny program developers are not interested to include these
register variables, because the tiny programs never requires
more time complete its job. These register variables may be
used to store constant values so as to make use of it
anywhere in the programs.
main{ register float a=0;}
Is This Answer Correct ? | 19 Yes | 1 No |
Post New Answer View All Answers
Difference between Function to pointer and pointer to function
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
Can two or more operators such as and be combined in a single line of program code?
What does sizeof return c?
What is the acronym for ansi?
Explain how can I convert a string to a number?
Explain the red-black trees?
What is a pointer in c plus plus?
Once I have used freopen, how can I get the original stdout (or stdin) back?
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?
What are reserved words with a programming language?
What are the advantages and disadvantages of a heap?
What are high level languages like C and FORTRAN also known as?
What is the use of sizeof () in c?
What are the salient features of c languages?