ex1

command
v0.0.0-...-17a1818 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 1 Imported by: 0

README

Exercise 1

Question

Write a program where you declare an integer variable called i with the value 20. Assign i to a floating point variable named f. Print out i and f.

Solution

The key here is that you need to use a type conversion to convert i to a float64 so it can be assigned. Go doesn't have automatic type promotion. Notice in our code that you don't need to specify the type for i or f; it can be inferred from the right hand side. The default type for an integer literal is int, so i's type can be inferred. The float64 type conversion on the right hand side of f's declaration specifies f's type.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL