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
12
votes
5 answers

Difference between public static and private static variables

class Employee{ // salary variable is a private static variable private static double salary; // DEPARTMENT is a constant public static final String DEPARTMENT = "Development"; public static void main(String args[]){ salary = 1000; …
Android Girl
  • 2,074
  • 3
  • 22
  • 29
12
votes
6 answers

SQL Server 2008 SELECT * FROM @variable?

It is possible? DECLARE @vTableName varchar(50) SET @vTableName = (SELECT TableName FROM qms_Types WHERE Id = 1) SELECT * FROM @vTableName I have this error: Msg 1087, Level 16, State 1, Line 3 Must declare the table variable "@vTableName".
soamazing
  • 1,656
  • 9
  • 25
  • 32
11
votes
3 answers

How to find the name of a variable that was passed to a function?

In C/C++, I have often found it useful while debugging to define a macro, say ECHO(x), that prints out the variable name and its value (i.e. ECHO(variable) might print variable 7). You can get the variable name in a macro using the…
James
  • 3,191
  • 1
  • 23
  • 39
11
votes
4 answers

Overriding interface's variable?

As I read from various Java book and tutorials, variables declared in a interface are constants and can't be overridden. I made a simple code to test it interface A_INTERFACE { int var=100; } class A_CLASS implements A_INTERFACE { int…
Alfred Zhong
  • 6,773
  • 11
  • 47
  • 59
11
votes
2 answers

Notation __no_init __root C

Hello guys I was reading a C source and I found a notation like this: __no_init __root extern volatile unsigned char var[10] @ 0x4000000; But I've no idea what that __no_init __root means, is it standard C? Thank you.
alkz
  • 337
  • 2
  • 7
  • 17
11
votes
3 answers

do I need to restore all variables onResume?

I had bad experience with static class variables since their values are lost when the class unloads. Therefore I avoid them alltogether. Now I am (probably overly) worried even with "normal" variables. I'm not sure if their value also might get…
user387184
  • 10,953
  • 12
  • 77
  • 147
11
votes
3 answers

Adding two Variables together?

Trying to add two integer variables together, however, I can't seem to figure it out as it just joins them as strings? var age_child = 10; var age_gap = 10 alert(age_child+age_gap); Result: 1010, Want Result: 20
ritch
  • 1,760
  • 14
  • 37
  • 65
11
votes
6 answers

read variables from wp-config.php

I'm busy writing a basic migration scripts for some WP sites, and i'm trying to automate creating mysql database and user credentials from reading the wp-config file how can i read the following variables from the wp-config file so that i…
anthonysomerset
  • 546
  • 4
  • 14
11
votes
9 answers

reuse of variables

I'm working on project that need do call the same method several times, but with different arguments. Can I use the same variable or do I have to declare another variable? For example: HttpWebRequest req =…
The Mask
  • 17,007
  • 37
  • 111
  • 185
11
votes
4 answers

In PHP, how do I add to a zero-padded numeric string and preserve the zero padding?

If I have a variable in PHP containing 0001 and I add 1 to it, the result is 2 instead of 0002. How do I solve this problem?
Ryan
  • 341
  • 3
  • 8
  • 21
11
votes
11 answers

How to print_r $_POST array?

I have following table.

Iladarsda
  • 10,640
  • 39
  • 106
  • 170
11
votes
2 answers

How to use sass global variables from other components in vite/vue3

I want to use and change global variables from other components, my files structure looks like this... I have my variables in global.sass file, but I can't access variables in other components.
AYM
  • 131
  • 1
  • 1
  • 5
11
votes
3 answers

Variable inside variable gitlab ci

Is there a way to use predefined variable inside custom variable in gitlab ci like this: before_script: - cat "${$CI_COMMIT_REF_NAME}" >> .env to extract the name of branch from $CI_COMMIT_REF_NAME and use it as a name of custom variable Update:
wspven
  • 115
  • 1
  • 2
  • 8
11
votes
8 answers

In Javascript, == "" evaluates to true. Why is it so?

If I do 0 == "0" it evaluates to true. Try, if( -777 == "-777" ) alert("same"); alert happens. And, it's also noticeable that true == "true" doesn't evaluate to true. Try, if( false == "false" ) alert("same"); alert doesn't happen. Why is it so?
Real Red.
  • 4,991
  • 8
  • 32
  • 44
11
votes
4 answers

shared variable across multiple class instances that I can change outside the class

the code explains it better: class Class{ $var = 0; function getvar() echo $this->var; } } $inst1 = new Class(); // I want to change $var here to 5 $inst2 = new Class(); echo $inst2->getvar(); // should be 5 Is it possible
pulă
  • 121
  • 1
  • 4