what is the difference between static variable and register
variable?

Answers were Sorted based on User's Feedback



what is the difference between static variable and register variable?..

Answer / 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

what is the difference between static variable and register variable?..

Answer / koti pendem

static variables stored in initialised data segment,where as
register variables stored in registers

Is This Answer Correct ?    18 Yes 1 No

what is the difference between static variable and register variable?..

Answer / amit

static variable stored in RAM where as register variable
stored in CPU's register ,
we can find address of static variable which is not
possible in case of register variable

Is This Answer Correct ?    10 Yes 1 No

Post New Answer

More C Interview Questions

What are the 5 elements of structure?

0 Answers  


Write a program to produce the following output in c language? 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

2 Answers  


Explain what is meant by high-order and low-order bytes?

0 Answers  


Is c pass by value or reference?

0 Answers  


Can you please explain the difference between malloc() and calloc() function?

0 Answers  






main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output?

9 Answers   Ramco,


Write a program to find whether the given number is prime or not?

6 Answers  


What is meaning of tree

0 Answers  


Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning

4 Answers   Accenture,


Explain what is the heap?

0 Answers  


Explain how can I read and write comma-delimited text?

0 Answers  


What are the benefits of organizational structure?

0 Answers  


Categories