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 ]

Basic types

Types that you'll use the most often:

let
  a = 42      # int is int64 (8 bytes) on a 64-bit system
  pi = 3.14   # float is float64 (8 bytes) on a 64-bit system
  s = "nim"   # string
  ok = true   # bool (1 byte)
  c = 'x'     # char (1 byte)

Integer types:

int        # signed, 64-bit long on a 64-bit system
int8       # 8 bits, i.e. 1-byte long
int16
int32
int64

uint       # unsigned, 64-bit long on a 64-bit system
uint8      # 8 bits, i.e. 1-byte long
uint16
uint32
uint64

Type info #1:

import typetraits  # echo n.type.name

proc main() =
  let a = 42          # has type int

  echo a              # 42
  echo a.sizeof       # 8 (8 bytes in the memory)
  echo a.type.name    # "int" (as string)
  echo a.low          # -9223372036854775808 (smallest possible value)
  echo a.high         # 9223372036854775807 (largest possible value)

  echo int.low        # -9223372036854775808 (works with types too)
  echo int.high       # 9223372036854775807 (works with types too)

Type info #2:

let
  a = 42
  b = true
  c = 'A'

echo typeof(a)    # int

echo typeof(b)    # bool

echo typeof(c)    # char

let s: string = $typeof(a)
echo s            # "int" as string

Integer literals in various number systems:

let
  decimal = 42
  hex = 0xffff
  octal = 0o644
  binary = 0b1111_0101

Type suffixes:

nim> 42'i8
42 == type int8

nim> 42'u8
42 == type uint8

nim> 3.14'f32
3.14 == type float32

nim> 3.14
3.14 == type float64

In C, 3.14 is a double. Here, it's called a float or float64. The type float is a float64 on a 64-bit system.

Char type

Like in C, a char is just 1 byte.

let
  a1 = 'A'
  a2 = '\x41'   # also 'A', given in hexa

  special = 'é' # ERROR, it's 2 bytes in UTF-8

  ok = "é"      # stored as a string
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, 15:55