{
  "id": "enwiki-001363948323",
  "slug": "dynamic-variable",
  "title": "Dynamic variable",
  "qid": "",
  "lead": "In computer programming, a dynamic variable is a local variable that is created to reside in manually allocated memory that can be allocated and deallocated. It is divided into three types, namely implicit heap dynamic variable, explicit heap dynamic variable and lost heap dynamic variable (dangling pointers). It has indefinite scope and dynamic extent. It is mostly used in niche programming languages which include Lisp, Ruby, APL, PHP, TcL, TEX and PERL.",
  "body": "In computer programming, a dynamic variable is a local variable that is created to reside in manually allocated memory that can be allocated and deallocated. It is divided into three types, namely implicit heap dynamic variable, explicit heap dynamic variable and lost heap dynamic variable (dangling pointers). It has indefinite scope and dynamic extent. It is mostly used in niche programming languages which include Lisp, Ruby, APL, PHP, TcL, TEX and PERL. let l = 10; // value stored in heap memory implicitly let b = 20; area = l * b; Explicit heap dynamic variable – Dynamic variables that are allocated and deallocated by explicit run–time instructions as specified by the programmer. Few examples are dynamic objects in C++ and objects in Java. int main() { int* y = new int(1); // creating dynamic variable *y for (int i = 0; i Lost heap dynamic variable – Dynamic variables which are no longer referenced by the pointer. When the heap dynamic variable is lost, the process is called memory leak. It is created by a first pointer pointing to a new heap dynamic variable and then the pointer is shifted to another heap dynamic variable. In memory leak, if the first heap dynamic variable is not used, it will be lost. int *a = new int(10); // allocating to heap dynamic variable a = new int(20); // re-allocating to same variable without freeing memory Dynamic objects are created in main method when the number of objects to be used is unknown thus making it more flexible than static objects by allowing dynamic memory allocation. In the below snippet, the constructor class Counter is automatically invoked when dynamic object *c is created and the value 5 is assigned. When the control deletes ( delete ) the object, the destructor ~Counter is called and the output gets printed. class Counter { int value; public: Counter(int start) { // Constructor called on object initialization value = start; } ~Counter() { // Destructor called when object destroyed value--; cout",
  "categories": [
    "104343312",
    "104343315",
    "11060667",
    "128821436",
    "23110049",
    "23603337",
    "24043274",
    "26220375",
    "26748027",
    "28043571",
    "31347309",
    "98501778"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1363948323",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1783944044.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001363948323",
    "type": "webpage",
    "title": "Dynamic variable",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/dynamic-variable",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          19
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          19
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001363948323",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1363948323",
    "note": "Immutable snapshot enwiki-001363948323"
  }
}