FACTOID # 16: Only two countries in the world are doubly landlocked: Liechtenstein and Uzbekistan.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Static variable

In computer programming, static variables typically have a broader scope than other variables. Their values may be set at run-time or may change subtly during program execution. Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. ... In computer programming in general, a scope is an enclosing context. ... In computer science, runtime describes the operation of a computer program, the duration of its execution, from beginning to termination (compare compile time). ...

Contents

For constants

Computer programs may store constants in constant variables or in static variables, depending on the available features of the programming language. For example, a program that uses an approximation of pi might be easier to write, read, and maintain with a variable called "PI" instead of multiple occurrences of "3.14159" A computer program is a collection of instructions that describe a task, or set of tasks, to be carried out by a computer. ... In mathematics and the mathematical sciences, a constant is a fixed, but possibly unspecified, value. ... A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. ... When a circles diameter is 1, its circumference is π. Pi or π is the ratio of a circles circumference to its diameter in Euclidean geometry, approximately 3. ...


For scope

Main article: Scope (programming)

In the C programming language, static is used with global variables and functions to set their scope to the containing file. In local variables, static is used to store the variable on the heap instead of in the transient call stack. This persists the value of the variable through subsequent function calls. In computer programming in general, a scope is an enclosing context. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...


For local variables

Main article: Local variable

Most programming languages include the feature of subroutines. Variables local to subroutines (local variables) are usually created and destroyed within the subroutine itself (so-called automatic variables). Some languages, however, (e.g., the C programming language) allow subroutines to retain the value of variables between calls, so that the function can preserve its state if necessary. For example, a static variable can record the number of times its subroutine has been executed. Doing so is otherwise possible using global variables or external storage, like a file on disk. In computer science, a local variable is a variable that is given local scope. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ... In computer science, a local variable is a variable that is given local scope. ... Automatic variables are variables local to a block. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... In computer programming, a global variable is a variable that does not belong to any subroutine in particular and can therefore can be accessed from any context in a program. ...


For class variables

Object-oriented programming languages use classes and objects. In this case, a class variable means a variable that can be seen and modified by all methods (called member functions in C++) of the class. This means, for example, that if the value of a class variable is changed by any method of the owning class, then all other methods of that class will see the changed value. In C++, class variables are known as static data members. In object-oriented programming, a class is a programming language construct that is used to group related instance variables and methods. ... Object-oriented programming (OOP) is a programming paradigm that uses objects to design applications and computer programs. ... In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete...


C# Example

 public class Request { private static int count; private string url; public Request() { //Create a new instance of Request //Count all requests Request.count++; } public string Url { get { return this.url; } set { this.url = value; } } public static int Count { get { //Do not use the this keyword here //as this refers to "THIS INSTANCE" return Request.count; } //Do not allow the developer to SET this value } } 

C++ Example

 class Request { private: static int count; string url; public: Request() { count++; } string Url(string value) { url = value; return url; } int Count() const { return count; } }; 

In this sample count applies to the class, while url applies to each instance.


See also

In computer science and mathematics, a variable (IPA pronunciation: ) (sometimes called a pronumeral) is a symbolic representation denoting a quantity or expression. ... In computer programming, thread-local storage is static or global memory local to a thread. ... The tone or style of this article or section may not be appropriate for Wikipedia. ...

References


  Results from FactBites:
 
Cprogramming.com - Tutorials - The Static Keyword in C++ (1030 words)
While most variables declared inside a class occur on an instance-by-instance basis (which is to say that for each instance of a class, the variable can have a different value), a static member variable has the same value in any instance of the class and doesn't even require an instance of the class to exist.
Static member functions are functions that do not require an instance of the class, and are called the same way you access static member variables -- with the class name rather than a variable name.
Static member functions can be used to modify static member variables to keep track of their values -- for instance, you might use a static member function if you chose to use a counter to give each instance of a class a unique id.
PHP: Variable scope - Manual (4975 words)
Static variables may be declared as seen in the examples above.
It should be noted that a static variable inside a method is static across all instances of that class, i.e., all objects of that class share the same static variable.
The variable is static with respect to the function and not the class.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.