what is the difference between static variable and register
variable?
Answers were Sorted based on User's Feedback
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 |
static variables stored in initialised data segment,where as
register variables stored in registers
| Is This Answer Correct ? | 18 Yes | 1 No |
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 |
what is the flow of execution in cprogram? ex:printf();,scanf();
What is the code in while loop that returns the output of given code?
What is the output from this program? #include <stdio.h> void do_something(int *thisp, int that) { int the_other; the_other = 5; that = 2 + the_other; *thisp = the_other * that; } int main(void) { int first, second; first = 1; second = 2; do_something(&second, first); printf("%4d%4d\n", first, second); return 0; }
How do I use void main?
#define DCHAR char* typedef char* TCHAR; if using these following variables will be declared like DCHAR ch1, ch2; TCHAR ch3, ch4; then what will be types of ch1, ch2, ch3 and ch4?
void main() { int a=1; while(a++<=1) while(a++<=2); }
define c
what is the difference between normal variables and pointer variables..............
15 Answers HP, Infosys, Satyam, Vivekanand Education Society,
to get a line of text and count the number of vowels in it
Explain how do you list a file’s date and time?
How many keywords (reserve words) are in c?
Hi, main() { } Is a user defined function or Built in Functionn