Golang Basics & Syntax Quiz
40 in-depth questions covering Go's fundamentals, packages, imports, syntax rules, variables, constants, comments, and formatting — with 10 code examples to solidify understanding.
Question 1
What is the primary design goal of the Go programming language?
Question 2
Which statement about Go packages is correct?
Question 3
What is the correct syntax for importing a package in Go?
Question 4
Which of these is a valid Go identifier?
Question 5
What is the difference between var and := in Go?
Question 6
What will this code print?
package main
import "fmt"
func main() {
var x int = 10
y := 20
fmt.Println(x + y)
}Question 7
Which of these constant declarations is valid?
Question 8
What does gofmt do?
Question 9
What is the output of this program?
package main
import "fmt"
func main() {
const x = 10
const y = x * 2
fmt.Println(y)
}Question 10
Which comment style is preferred in Go?
Question 11
What happens when you declare a variable without initializing it?
Question 12
What is the purpose of the main package in Go?
Question 13
What will this code output?
package main
import "fmt"
func main() {
var a int
b := a
fmt.Printf("%d %d\n", a, b)
}Question 14
Which import style allows renaming a package?
Question 15
What is the output of this constant expression?
package main
import "fmt"
func main() {
const (
a = iota
b
c
)
fmt.Println(a, b, c)
}Question 16
Why does Go require explicit package imports?
Question 17
What will this program print?
package main
import "fmt"
func main() {
x := 10
{
x := 20
fmt.Print(x, " ")
}
fmt.Println(x)
}Question 18
Which of these is NOT a basic syntax rule in Go?
Question 19
What is the result of this variable declaration?
package main
import "fmt"
func main() {
var x, y int = 1, 2
fmt.Println(x, y)
}Question 20
What does the blank identifier _ do in Go?
Question 21
What is the output of this import example?
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("Hello")
}Question 22
Which constant declaration is invalid?
Question 23
What will this code print?
package main
import "fmt"
func main() {
const x = 5
var y = x
fmt.Println(y)
}Question 24
Why does Go have gofmt?
Question 25
What is the output of this scoping example?
package main
import "fmt"
var x = 10
func main() {
fmt.Println(x)
x := 20
fmt.Println(x)
}Question 26
Which of these package names is conventional for an executable?
Question 27
What will this code output?
package main
import "fmt"
func main() {
var x int
x = 5
fmt.Println(x)
}Question 28
What is the purpose of the init function in Go?
Question 29
What is the output of this constant group?
package main
import "fmt"
func main() {
const (
a = 1 << iota
b
c
)
fmt.Println(a, b, c)
}Question 30
Why are semicolons optional in Go?
Question 31
What will this program print?
package main
import "fmt"
func main() {
x := 10
if x > 5 {
fmt.Println("Big")
}
}Question 32
Which of these is a valid comment in Go?
Question 33
What is the output of this variable shadowing scenario?
package main
import "fmt"
func main() {
x := 1
{
x := 2
fmt.Print(x)
}
fmt.Println(x)
}Question 34
What makes Go's syntax different from C-like languages?
Question 35
What will this code output?
package main
import "fmt"
func main() {
const a = "Hello"
const b = a + " World"
fmt.Println(b)
}Question 36
Why does Go require packages for all files?
Question 37
What is the output of this import alias example?
package main
import f "fmt"
func main() {
f.Println("Hello")
}Question 38
Which of these variable declarations is invalid at package level?
Question 39
What is the purpose of gofmt in the Go toolchain?
Question 40
What fundamental concept does Go's basic syntax emphasize?
