answersLogoWhite

0


Best Answer

Static variables exist for the entire duration of the program. Therefore a static character variable is a character that exists for the entire duration the program is running. Regardless of where a static variable is declared and initialised, it is physically instantiated and initialised when the program loads. If the variable has function scope, whatever value is currently assigned to the variable will remain in effect the next time that function is called, but only the function can modify the variable. If the variable has class scope, then the variable exists even if no instances of the class have yet been instantiated, but any and all instances share the variable (it is common to the class, not to any one instance of the class). Static class variables must be initialised outwith the class body and outwith any other function body, but can only be modified by the class members (both static and non-static) and by friends of the class. If the variable has file scope, then the variable is a global variable. Global variables are largely frowned upon as there's no way to control what code can modify the value. Passing local function variables to other functions is the preferred method as this gives much greater control over which code can access and/or modify the value, as well as limiting the lifetime of the variable. To ensure the variable exists throughout a program's lifetime (as per a static variable), instantiate the variable from within the program's entry point.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the advantage of static character variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the semistatic character variable?

The semi static character variable is often the plot, if the plot changes, the semi static character may change as well.


What is the difference between a static variable a global variable and a local variable?

A static variable is a variable allocated in static storage. A local variable is a variable declared inside a function. A global variable is a variable declared outside of any class or function. Note that local variables and global variables can both be allocated in static storage.


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


How do you create static variables in PHP?

Use the "static" keyword to declare a static variable within a function like shown below. <?php function fun() { static $variable; static $another_variable = ''; } ?>


Why use static variable in programming language?

For C programming, the use of a static variable has two uses: One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in. The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.


Can static variable be used inside a static method?

Yes.


What is static variable and how it is declared?

static variables are declared to define a variable as a constant., means if you declare a variable as static the variable becomes costant.syntaxstatic int a=100;this will make the value of a as 100 which is not to be changedWell, no; you think of 'const', which can be used together with static, but not necessarily.Yes you are right bro I was confused it should be const int a=100; then the variable will be a constant.


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


What is the static variable in the class in c?

A static member variable is local to the class rather than to an object of the class.


Is Salva a static or dynamic character?

He is a static character


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


Was Horatio in Hamlet static or dynamic?

The character named Horatio in Hamlet is a dynamic character.