# Primitive Data Types in Go

Unlike languages like Python and Javascript, Go is statically typed. That means once a variable type is defined, the variable will only store that type of data.

Go has 3 basic types

1. bool
    
2. Numeric
    
3. string
    

### **Bool**

To declare a variable and then initalize it, you can do it following way:

```go
var myVar bool 					//type declaration
myVar = false 					//value initialization
var myVar2 bool = false //type declaration and initialization
```

There is a special short cut operator to declare and define variables in Go:

```go
myVar := false
```

In the above code, using the `:=` operator, we can directly declare and assign the variable a value. The type is automatically inferred from the value.

### **Integers**

There are two types of integers

1. Signed integers
    
2. Unsigned integers
    

Signed integers are declared with the int prefixed keywords

```go
var x int = 200
var y int8 = -100 
```

There are five types of int:

1. int -&gt; 32 bits for 32 bit systems and 64 bits for 64 bit systems.
    
2. int8 -&gt; 8 bit integer storing from -128 to 127
    
3. int16 -&gt; 16 bit integer storing from -32768 to 32767
    
4. int32 -&gt; 32 bit integer storing from +/- 2^31
    
5. int64 -&gt; 64 bit integer storing from +/- 2^63
    

You can use these keywords to define integers.

Unsigned integers can be defined using uint prefixed key

```go
var x uint = 1200
var x uint16 = 2456
```

Similar to int, you have five types of uint

1. int -&gt; 32 bits for 32 bit systems and 64 bits for 64 bit systems.
    
2. int8 -&gt; 8 bit storing positive values from 0 to 2^8
    
3. int16 -&gt; 16 bit storing positive values from 0 to 2^16
    
4. int32 -&gt; 32 bit storing positive values from 0 to 2^32
    
5. int64 -&gt; 64 bit storing positive values from 0 to 2^64
    

There are two aliases for uint8 and int32

1. btye -&gt; alias for uint8
    
2. rune -&gt; alias for int32
    

```go
var m rune = -42
var n byte = 37
fmt.Println(reflect.TypeOf(m), reflect.TypeOf(n))
```

`m` will be `int32` whereas n will be `uint8`

### **Float**

There are two types of floats

1. float32 -&gt; 32 bit float storing from -3.4e+38 to 3.4e+38
    
2. float64 -&gt; 64 bit float storing from -1.7e+308 to 1.7e+308
    

The default type is float64 in case you use `:=` for defining a variable.

```go
x := 3.44				//float64
var y float32 = 3e+38
var y float64 = 17.323
```

### **String**

Strings can be defined using the `string` keyword

```go
var x string = "Hello, World!"
y := "My name is awesome!"
```

### **Complex**

Go also supports complex numbers as follows

```go
a := complex(1.2, 3.4)
var b complex128 := complex(1.2, 3.4)
c := 8 + 7i
```

Complex numbers is the same mathematical concept where you had a real and an imaginary number. Both the real and imaginary part are floats either float32 or float64.

Complex numbers can be either 128bit or 64bit

1. complex128 -&gt; 64bit f real + 64bit imaginary
    
2. complex64 -&gt; 32bit real + 32bit imaginary
    

### **Zero Values**

Following are the zero values, which are given when variables are declared without initializing

1. `0` for numeric types
    
2. `false` for boolean type
    
3. `""` for strings
    

### **Null**

In Golang, `null` is replaced with `nil`. We will talk more about `nil` when discussing pointers and interfaces.
