Golang (Go) Tutorial - Variables & Data Types
๐ฆ Variables Aur Data Types
๐ Storage Boxes:
๐ฆ Variable = Box (data store karo)
๐ท๏ธ Type = Label (kya type ka data)
๐ Value = Content (actual data)
๐ Data Types in Go
| Type | Example | Use |
|---|---|---|
| int | 25, -10 | Numbers (whole) |
| float64 | 3.14, 25.5 | Decimals |
| string | "Hello" | Text |
| bool | true, false | Yes/No |
๐ Variable Declaration
3 Ways
// Way 1: Full declaration
var name string = "Rohan"
// Way 2: Type inference
var age = 25
// Way 3: Short declaration (most common)
city := "Delhi"
๐ก Go Features:
- Type inference - Type auto detect
- := operator - Quick declaration
- Unused variables = Compile error!
Example
name := "Rohan"
age := 25
fmt.Println(name, age)