What is meant by global static? why we have to use static
variable instead of Global variable

Answer Posted / indira amit

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. 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.

Had it been gloal variable, it would have been available
outside the scope of the function, but static variable is
not available outside the scope of a function (helpful in
localizing errors - as it can't be changed outside the func
scope).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c fast?

606


Is exit(status) truly equivalent to returning the same status from main?

587


A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

1777


the question is that what you have been doing all these periods (one year gap)

1618


What are the different types of data structures in c?

608






What are the 5 organizational structures?

569


What does printf does?

747


What are different types of variables in c?

571


Explain can static variables be declared in a header file?

682


What are preprocessor directives in c?

638


What is the process to generate random numbers in c programming language?

610


Is there anything like an ifdef for typedefs?

704


What is && in c programming?

683


How can I ensure that integer arithmetic doesnt overflow?

608


What is the function of volatile in c language?

668