answersLogoWhite

0

A static variable in C is a variable whose value and memory allocation persists throughout the execution of the program. If the variable is declared at file scope (outside of any blocks) the static attribute means the variable is visible only to the file containing it, i.e. it can not be referenced through an extern reference in a different file.

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


When an array is declared does c automatically initializes its elements to zero?

For global/static variables: yes.For auto variables: no.


Are static variables serialized in java?

No, static variables are not serialized.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


Static variable in c plus plus?

There are two uses for a static variable in C++. When declared outside of a class, a variable is regarded as being global. However a static variable is deemed local to the file in which it is declared. That is, the variable is scoped to the file, and cannot be accessed by code outside of that file. This aspect was inherited from C. C++ also allows static variables to be declared inside a class. In this case, the variable is local to the class. By contrast, instance variables (non-static member variables) are local to each instance of the class. With static variables, there is only one instance of each variable which can be shared by all instances of the class. It is not unlike a global but it is scoped to the class. Since all static variables are instantiated at compile time, they exist for the entire duration a program runs. Even if they fall from scope, they never lose their value. Static variables defined within a class are also available even when no instances of the class are instantiated. Their visibility outside of the class is dependent upon whether they are declared public, protected or private.

Related Questions

Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


When an array is declared does c automatically initializes its elements to zero?

For global/static variables: yes.For auto variables: no.


Are static variables serialized in java?

No, static variables are not serialized.


What are global variables in c?

The ones that are declared outside any functions and don't have modifier static.


Can static variables be declared in a header file in C programming?

Yes (but usually it is a bad idea).


Why static functions cannot use instant variables?

Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


How do you access the static variable and static methods of a class?

In java we access static variables and static methods without creating objects. i.e.,we can access directly by using classname we can also access static variables and static methods by using objects which are created by using class where the static variables and static methods are available


What are the storage classes in c?

A storage class defines the visibility and lifetime of variables or/and functions within a C Program. There are following storage classes which can be used in a C Program: auto register static extern


Can variables be changed?

A static variable is one which is not stored on the stack but in the memory of the program. Static variables can be changed.


Static variable in c plus plus?

There are two uses for a static variable in C++. When declared outside of a class, a variable is regarded as being global. However a static variable is deemed local to the file in which it is declared. That is, the variable is scoped to the file, and cannot be accessed by code outside of that file. This aspect was inherited from C. C++ also allows static variables to be declared inside a class. In this case, the variable is local to the class. By contrast, instance variables (non-static member variables) are local to each instance of the class. With static variables, there is only one instance of each variable which can be shared by all instances of the class. It is not unlike a global but it is scoped to the class. Since all static variables are instantiated at compile time, they exist for the entire duration a program runs. Even if they fall from scope, they never lose their value. Static variables defined within a class are also available even when no instances of the class are instantiated. Their visibility outside of the class is dependent upon whether they are declared public, protected or private.


Can non static methods can access static variables?

Yes, they can