Intel Corporation interview question

Static keyword

Interview Answers

Anonymous

Oct 28, 2012

In C language: static variable: 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). - known to the file static function is private to the c file and can't be included to other files

Anonymous

Mar 30, 2011

gwgw