Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2024/25/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Static vs. dynamic array

(1) static vs. dynamic array
import std.stdio;

// static array in D

void main()
{
    int[3] scores;
    writeln(scores); // [0, 0, 0]

    int[5] numbers = [1, 2, 3, 4, 5];
    writeln(numbers); // [1, 2, 3, 4, 5]

    numbers = 1; // set ALL elements to 1
    writeln(numbers); // [1, 1, 1, 1, 1]
}
import std.stdio;

// dynamic array in D

void main()
{
    int[] numbers;

    writeln(numbers); // []
    writeln(numbers.length); // 0

    numbers.length = 5;
    writeln(numbers); // [0, 0, 0, 0, 0]

    int[] scores;
    scores ~= 1;
    scores ~= 2;
    scores ~= 3;
    writeln(scores); // [1, 2, 3]
}

In Python, a dynamic array is called a list. In D, a dynamic array is also called a slice.

Throughout these notes, I'll use the terms list and slice as synonyms to denote dynamic arrays.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 June 28, 15:15