ADVERTISEMENT
ADVERTISEMENT

What form of type conversion does Go support?

Learn about the conversion in Go language, what form of type conversion does Go support?
Submitted by IncludeHelp, on October 04, 2021

Go programming language supports explicit type conversion. It does not support implicit type conversion due to its strong type system.

Consider the syntax,

new_type (variable/value)

Example:

// Golang program to demonstrate the
// example of explicit type conversion

package main

import "fmt"

func main() {
	var VarInt int
	var VarFloat float32

	VarFloat = 123.45
	// Converting float32 to int
	VarInt = int(VarFloat)

	// Printing the values
	fmt.Println(VarInt)
	fmt.Println(VarFloat)
}

Output:

123
123.45

Golang FAQ »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.