Recall & Review
beginner
What is package scope in Go?
Package scope means that a variable, function, or type is accessible anywhere within the same package but not outside it.
Click to reveal answer
beginner
How do you make a function or variable accessible outside its package in Go?
By starting its name with an uppercase letter, making it exported and accessible from other packages.
Click to reveal answer
beginner
Given this code snippet, where is the variable accessible?
package main
var count int = 5
func main() {
// ...
}The variable 'count' is accessible anywhere inside the 'main' package but not from other packages.
Click to reveal answer
intermediate
What happens if two files in the same package declare variables with the same name at package scope?
It causes a compile-time error because package scope variables must have unique names within the package.
Click to reveal answer
intermediate
Explain the difference between package scope and block scope in Go.
Package scope means the identifier is visible throughout the entire package, across all files. Block scope means the identifier is only visible within the enclosing block where it is declared (e.g., inside a function or if statement).
Click to reveal answer
In Go, how do you make a variable accessible outside its package?
✗ Incorrect
In Go, identifiers starting with uppercase letters are exported and accessible outside their package.
Where can a package-scoped variable be accessed?
✗ Incorrect
Package scope means the variable is accessible anywhere within the same package.
What happens if two package-scoped variables have the same name in the same package?
✗ Incorrect
Go does not allow duplicate package-scoped variable names in the same package; it causes a compile-time error.
Which of these is NOT true about package scope in Go?
✗ Incorrect
Unexported package scope variables are NOT accessible from other packages.
If a variable name starts with a lowercase letter, what is its visibility in Go?
✗ Incorrect
Lowercase names are unexported and visible only inside their package.
Describe how package scope works in Go and how it affects variable and function visibility.
Think about uppercase vs lowercase naming.
You got /3 concepts.
Explain why two package-scoped variables cannot have the same name in Go and what error occurs if they do.
Consider how Go enforces uniqueness in package scope.
You got /3 concepts.