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 ]

Declaring variables

Nim is a statically typed language, meaning that the type of every variable is known and checked at compile time, rather than at runtime. However, Nim has some nice quality of life features, like type inference for instance. Once the type of a variable is determined, it cannot change in the future.

var vs let

In Python there are mutable (ex.: list, set) and immutable (ex.: string, tuple) data structures. In Nim mutability/immutability depends on how the variable was declared.

var: mutable

var a = 2          # type is inferred to int
var b: int = 10    # type is specified explicitly

a += 1

echo a  # 3

let: immutable

let a = 2          # type is inferred to int
let b: int = 10    # explicit type

a += 1  # error

const

It's similar to let. However, while the value of a let variable is determined at runtime, the value of a const variable is determined at compile time. It means that you must assign a value to a const variable that can be determined during the compilation.

We use let more often. If you want to make your program run faster, then you can use const variables.

A typical use case for const is when you need some global constants (named constants).

const
#include <stdio.h>

#define MAX 10

int main()
{
    printf("MAX: %d\n", MAX); // 10

    return 0;
}
const MAX = 10

proc main() =
  echo MAX  # 10

Here is a longer example for const.

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 03, 13:35