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

* 2025/26/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
* Nim2
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Static arrays

Nim has both static arrays (like in C) and dynamic arrays (like in Python). This time, let's see the static arrays.

Static arrays are fixed-sized arrays. Their size is decided upon creation and later it cannot be changed. A static array cannot grow or shrink.

static arrays
#include <stdio.h>

int main()
{
    int numbers[] = {2, 3, 7, 5};
    int n = sizeof(numbers) / sizeof(numbers[0]);

    printf("n: %d\n", n); // 4

    return 0;
}
var
  a: array[3, int] = [5, 7, 9]
  b = [2, 3, 7, 5]

  d: array[7, string]

echo b.len    # 4

a: we specify the type of the array and we initialize it

b: the type is inferred; the array is initialized

d: the array is declared but not initialized explicitly. It'll be initialized implicitly, and the array will contain 7 empty strings.

Since these arrays are var arrays, they are mutable. A let array would be immutable.

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 2026 April 06, 08:26