Skip to content

Commit c070aee

Browse files
committed
Tutorial2 - Constants Variables and Basic Data Types
1 parent abe32df commit c070aee

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ go run tutorial1/main.go
4343

4444
### Topics covered:
4545
- [x] [Basics](tutorial1)
46+
- [x] [Constants Variables and Basic Data Types](tutorial2)

tutorial2/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Constants, Variables and Basic Data Types in Go
2+
3+
## Constants
4+
5+
In Go, constants are declared like variables, but with the `const` keyword. Constants can be character, string, boolean, or numeric values. Constants cannot be declared using the `:=` syntax.
6+
7+
```go
8+
const Pi = 3.14
9+
```
10+
11+
12+
## Variables
13+
14+
Variables in Go are explicitly declared and used by the compiler to e.g. check type-correctness of function calls.
15+
16+
```go
17+
var x int = 1
18+
y := 2 // Short variable declarations, infer the type based on the assigned value
19+
```
20+
21+
## Basic Data Types
22+
23+
Go's basic types are:
24+
25+
```go
26+
bool
27+
28+
string
29+
30+
int int8 int16 int32 int64
31+
uint uint8 uint16 uint32 uint64 uintptr
32+
33+
byte // alias for uint8
34+
35+
rune // alias for int32, represents a Unicode code point
36+
37+
float32 float64
38+
39+
complex64 complex128
40+
```
41+
42+
The `int`, `uint`, and `uintptr` types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems.
43+
44+
## Zero Values
45+
46+
Variables declared without an explicit initial value are given their zero value. The zero value is:
47+
48+
- `0` for numeric types,
49+
- `false` for the boolean type, and
50+
- `""` (the empty string) for strings.
51+
52+
### Checkout the code
53+
54+
- [main.go](main.go)

tutorial2-ConstantsVariablesBasicDataTypes/main.go renamed to tutorial2/main.go

File renamed without changes.

0 commit comments

Comments
 (0)