Primitives
In Go, the distinction between "primitive types" and "composite types" is not as explicit as in some other languages. However, traditionally, primitive types are considered to be the basic building blocks for data manipulation.
Primitive types in Go:
- Numeric Types:
int
,int8
,int16
,int32
,int64
uint
,uint8
,uint16
,uint32
,uint64
float32
,float64
- String Type:
string
- Boolean Type:
bool
These types represent basic values and are not composed of other types. The other types such as arrays, slices, maps, structs, pointers, functions, and interfaces, are considered composite types because they are composed of multiple values or have more complex structures.
package main
import (
"fmt"
)
func main() {
// Numeric Types
var integer int = 42
var unsignedInt uint = 10
var floatingPoint float64 = 3.14
fmt.Println("Integer:", integer)
fmt.Println("Unsigned Integer:", unsignedInt)
fmt.Println("Floating Point:", floatingPoint)
// String Type
var myString string = "Hello, Go!"
fmt.Println("String:", myString)
// Boolean Type
var isTrue bool = true
fmt.Println("Boolean:", isTrue)
// Operations with Numeric Types
sum := integer + int(unsignedInt)
fmt.Println("Sum:", sum)
// String Operations
concatenatedString := myString + " Welcome!"
fmt.Println("Concatenated String:", concatenatedString)
// Boolean Operations
andResult := true && false
orResult := true || false
fmt.Println("AND Result:", andResult)
fmt.Println("OR Result:", orResult)
// Type Conversion
var intToFloat float64 = float64(integer)
fmt.Println("Integer to Float:", intToFloat)
}
Code Challenge
Calculates the area of different shapes.
Loading...
> code result goes here