# Basic types Every variable and data structure in Kotlin has a type. Types are important because they tell the compiler what you are allowed to do with that variable or data structure. In other words, what functions and properties it has. In the last chapter, Kotlin was able to tell in the previous example that `customers` has type [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/). Kotlin's ability to infer the type is called type inference. `customers` is assigned an integer value. From this, Kotlin infers that `customers` has a numerical type `Int`. As a result, the compiler knows that you can perform arithmetic operations with `customers`: ```KOTLIN fun main() { //sampleStart var customers = 10 // Some customers leave the queue customers = 8 customers = customers + 3 // Example of addition: 11 customers += 7 // Example of addition: 18 customers -= 3 // Example of subtraction: 15 customers *= 2 // Example of multiplication: 30 customers /= 3 // Example of division: 10 println(customers) // 10 //sampleEnd } ``` Tip: `+=`, `-=`, `*=`, `/=`, and `%=` are augmented assignment operators. For more information, see [Augmented assignments](operator-overloading.html#augmented-assignments). In total, Kotlin has the following basic types: | Category |Basic types |Example code | --------------------------------------- | [Integers](numbers.html#integer-types) |`Byte`, `Short`, `Int`, `Long` |`val year: Int = 2020` `val amount: Long = 350_000_000` | | [Unsigned integers](unsigned-integer-types.html) |`UByte`, `UShort`, `UInt`, `ULong` |`val score: UInt = 100u` | | [Floating-point numbers](numbers.html#floating-point-types) |`Float`, `Double` |`val currentTemp: Float = 24.5f` `val price: Double = 19.99` | | [Booleans](booleans.html) |`Boolean` |`val isEnabled: Boolean = true` | | [Characters](characters.html) |`Char` |`val separator: Char = ','` | | [Strings](strings.html) |`String` |`val message: String = "Hello, world!"` | For more information on basic types and their properties, see [Types overview](types-overview.html). With this knowledge, you can declare variables and initialize them later. Kotlin can manage this as long as variables are initialized before the first read. To declare a variable without initializing it, specify its type with `:`. For example: ```KOTLIN fun main() { //sampleStart // Variable declared without initialization val d: Int // Variable initialized d = 3 // Variable explicitly typed and initialized val e: String = "hello" // Variables can be read because they have been initialized println(d) // 3 println(e) // hello //sampleEnd } ``` If you don't initialize a variable before it is read, you see an error: ```KOTLIN fun main() { //sampleStart // Variable declared without initialization val d: Int // Triggers an error println(d) // Variable 'd' must be initialized //sampleEnd } ``` Now that you know how to declare basic types, it's time to learn about [collections](kotlin-tour-collections.html). ## Practice Declare explicit types for variables : Explicitly declare the correct type for each variable: : ```KOTLIN fun main() { val a: Int = 1000 val b = "log message" val c = 3.14 val d = 100_000_000_000_000 val e = false val f = '\n' } ``` : ```KOTLIN fun main() { val a: Int = 1000 val b: String = "log message" val c: Double = 3.14 val d: Long = 100_000_000_000_000 val e: Boolean = false val f: Char = '\n' } ``` ## See also * [Previous step](kotlin-tour-hello-world.html) * [Next step](kotlin-tour-collections.html)