Questions tagged [variables]

THIS IS AMBIGUOUS; USE SPECIFIC-LANGUAGE TAGS WHENEVER APPLICABLE. A variable is a named data storage location in memory. Using variables, a computer program can store numbers, text, binary data, or a combination of any of these data types. They can be passed around in the program.

A variable is a named data storage location in memory. Using variables a computer program can store numbers, textual data, , or a combination of any of these data types. The data can be passed around in a program by copying it from variable to variable or by referencing variables, i.e. defining from which variable a receiving code part is to take the contained data.

Variables which are only accessible within a certain function are termed "local variables". A "global variable", or one with indefinite scope, may be referred to anywhere in the program.

In some , variables are constrained by a specific data type. Data types may vary across languages, but share many commonalities.

Primitive data types usually include:

  • character, char, string, varchar (text)
  • byte, short, int, tinyint, integer, long (whole numbers)
  • double, decimal, float (real numbers)
  • bit, boolean (true/false)
  • date, datetime (date and time values)
  • object (any value, including composite types)
  • binary, raw, varbinary (that store stream of system data in binary form)

Composite data types consist of usually more than one of the primitive types and/or even other composite types.

# an example composite type, in pseudo code
Person(
    'First name'  : string,
    'Surname'     : string,
    'Birthday'    : date,
    'CanProgram'  : boolean
)

Some languages contain extra primitives: Tuples (Python), Linked Lists (Lisp), Hash Tables (Lisp, Perl, Python, Lua, D).

Some programming languages allow variables that store functions, that can be stored in data structures, passed as parameters to other functions, or returned as a result from other functions.

Memory allocation

The specifics of variable allocation and the representation of their values vary widely, both among programming languages and among implementations of a given language. Many language implementations allocate space for local variables (whose extent lasts for a single function call) on the stack, and their memory is automatically reclaimed when the function returns. More generally, in name binding, the name of a variable is bound to the address of some particular block (contiguous sequence) of bytes in memory, and operations on the variable manipulate that block. Referencing is more common for variables whose values have large or unknown sizes when the code is compiled. Such variables reference the location of the value instead of storing the value itself, which is allocated from a pool of memory called the heap.

More information and reference material on Wikipedia.

53839 questions
11
votes
2 answers

How can I use colon (:) in variable

I want to write code like this: index = 0:2 print(list[index]) but this does not work. Is there any way I can store all parts of the [...:...] syntax in a variable?
11
votes
3 answers

SQL Variable takes longer to return than static value

I have a table with two values: ciid, businessdate ciid is the primary key, and has auto increment turned on. businessdate (datetime) is inserted by another process. given the following queries: select top(1) ciid, businessdate from checkitemsales…
kloodge
  • 111
  • 4
11
votes
3 answers

Faster to declare variables inside a loop or outside a loop?

Is it faster to declare variables inside a loop or outside a loop? For example: ' Declaration inside of the loop For each item in items Dim newVariable as String = GetAString() Next ' Declaration outside of the loop Dim newVariable as String =…
Moderator71
  • 385
  • 7
  • 16
11
votes
2 answers

How to print out value of a variable during debugging in Netbeans?

In xcode during debugging, it is possible to print out the value of a variable at that particular stage. I was just wondering if there is a similar function in Netbeans? If not, what Java IDE does?
Thor
  • 9,638
  • 15
  • 62
  • 137
11
votes
2 answers

How should I refer to class variables in Python?

In Python I can refer to a class level variable with either ClassName.class_var or self.class_var from within a class. Now as long as I do not override the class level variables name within an object by creating an instance variable of the same name…
bmcentee148
  • 594
  • 1
  • 7
  • 18
11
votes
1 answer

how many character can set for string variable?

I have a variable with string type. For example string test;. How many character i can set for test? Thanks.
Farna
  • 1,157
  • 6
  • 26
  • 45
11
votes
14 answers

The importance of declaring a variable as unsigned

Is it important to declare a variable as unsigned if you know it should never be negative? Does it help prevent anything other than negative numbers being fed into a function that shouldn't have them?
Rarge
  • 155
  • 2
  • 5
11
votes
2 answers

how to set an expect variable with output of shell command

I want to set a variable b in expect file,here initially i did ssh to a machine through this script,in that machine I want to do fetch a value and set the expect variable using following command: set b [exec `cat /home/a |grep "work"|awk -F '='…
Ek1234
  • 407
  • 3
  • 7
  • 17
11
votes
5 answers

Limits on Windows environment variable nesting?

So, is there a limit to how deeply environment variables can be nested in Windows? I do a lot of development work and I'm trying to set up my development environment vars, and a lot of them nest off each other,…
trycatch
  • 111
  • 1
  • 3
11
votes
5 answers

How to get self into a Python method without explicitly accepting it

I'm developing a documentation testing framework -- basically unit tests for PDFs. Tests are (decorated) methods of instances of classes defined by the framework, and these are located and instantiated at runtime and the methods are invoked to…
kindall
  • 178,883
  • 35
  • 278
  • 309
11
votes
2 answers

What is the limit in size of a Php variable when storing string?

This is the case: I have a 2Gb dump file called myDB.sql. It is a dump file that deletes a existing database and creates a new one, with views and triggers. So I have the string myDB_OLD spread for many lines of the code. I would like to change…
IgorAlves
  • 5,086
  • 10
  • 52
  • 83
11
votes
4 answers

How to get all variable and method names used in script

It can be weird but I am looking for a way to get automatically all variables and method within a python script. For example, a = 1 b = 2 c = 3 myList = range(10) def someMethod(x): something = do_something() return something f =…
farhawa
  • 10,120
  • 16
  • 49
  • 91
11
votes
2 answers

Wildcards in variable path with Powershell

I would like in my script to use wildcard in variable like this : $TARGET = "\\MACHINE1\c$\ProgramData\Test\12.*\Data\" The problem is $TARGET returns \\MACHINE1\c$\ProgramData\Test\12.*\Data\ and…
robinwood13
  • 179
  • 1
  • 1
  • 8
11
votes
2 answers

Variable name length vs performance

How is it possible, that a huge difference in variable name length won't cause any performance loss in javascript? It takes the same time to declare var a = 0; as it takes to declare var aaaaaaaaaaaaaaa = 0; It takes the same time even to execute…
István Pálinkás
  • 2,217
  • 7
  • 25
  • 50
11
votes
4 answers

I have a require("config.php") with arrays, but still get Undefined variable error

I hava a function that looks something like this: require("config.php"); function displayGta() { (... lots of code...) $car = $car_park[3]; } and a config.php that look something like this:
ganjan
  • 7,356
  • 24
  • 82
  • 133