Variables

Type Converstion in Go

Type conversion is used to convert an object or variable of one type into another. Also known as typecast or type casting in other languages.


Syntax
var newVar newType
newVar = newType(anotherTypeVar) //assuming another variable declared

Notes

The Go specification provides rules on type conversions.


Example
package main

func main(){
    year := 2015 //inferred type int
    var yearString string
    yearString = string(year) //convert to string
}

< Primitive Data Types   |   Variable Declaration >

© 2019 SyntaxDB. All Rights Reserved.