Consider the following Go program. What will it print when run?
package main import "fmt" func main() { var a int = 5 var b float64 = 3.2 var c bool = true fmt.Println(a, b, c) }
Remember that fmt.Println prints values separated by spaces and booleans print as true or false.
The variables a, b, and c are printed as their values: integer 5, float 3.2, and boolean true.
What does this Go program print?
package main import "fmt" func main() { var x int = 10 var y float64 = float64(x) / 4 fmt.Printf("%.2f", y) }
Look at the Printf format specifier and the type conversion.
The integer 10 is converted to float64, then divided by 4, resulting in 2.5. The format %.2f prints two decimal places, so output is 2.50.
What error will this Go program cause when compiled?
package main func main() { var a int = "hello" println(a) }
Check the variable type and the assigned value type.
The variable a is declared as int but assigned a string. This causes a type mismatch error.
On a 64-bit system, how many bytes does the int type occupy in Go?
Think about the system architecture and Go's default int size.
On 64-bit systems, Go's int type is 64 bits, which equals 8 bytes.
Given the code below, what is the value of result after execution?
package main func main() { var a uint8 = 250 var b uint8 = 10 var result uint8 = a + b println(result) }
Remember that uint8 can only hold values from 0 to 255 and wraps around on overflow.
Adding 250 + 10 equals 260, but uint8 max is 255, so it wraps around: 260 - 256 = 4.