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

Where local variables are stored in c?

552


What is #include stdio h?

676


Is c# a good language?

602


What does do in c?

601


Can we access the array using a pointer in c language?

554






What is the importance of c in your views?

586


What is malloc calloc and realloc in c?

660


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

1899


Where in memory are my variables stored?

628


Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

594


What is a nested formula?

598


Explain what are the standard predefined macros?

647


how to count no of words,characters,lines in a paragraph.

3896


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

583


What is c variable?

548