D. Function name should start with uppercase to be accessible
Solution
Step 1: Check function visibility rules
In Go, only functions starting with uppercase letters are exported and accessible outside their package.
Step 2: Identify the function name issue
The function is named 'helper' (lowercase), so it is not accessible from main package.
Final Answer:
Function name should start with uppercase to be accessible -> Option D
Quick Check:
Lowercase function = not exported [OK]
Hint: Exported functions start uppercase [OK]
Common Mistakes:
Thinking package name must be Main
Believing import path must be URL
Assuming fmt.Println can't print function output
5. You want to create a custom package stringutil with a function Reverse that reverses a string. Which of the following is the correct way to define and use it in your main.go?
hard
A. In stringutil package: func Reverse(s string) string { /* code */ } In main.go: import "stringutil" and call Reverse("hello")
B. In stringutil package: func reverse(s string) string { /* code */ } In main.go: import "stringutil" and call stringutil.reverse("hello")
C. In stringutil package: func Reverse(s string) string { /* code */ } In main.go: import "stringutil" and call stringutil.Reverse("hello")
D. In stringutil package: func Reverse(s string) string { /* code */ } In main.go: no import needed, call Reverse("hello")
Solution
Step 1: Define exported function in package
The function must start with uppercase 'Reverse' to be accessible outside the package.
Step 2: Import package and call function with package name
In main.go, import "stringutil" and call the function as stringutil.Reverse("hello").
Final Answer:
Define func Reverse and call stringutil.Reverse("hello") after import -> Option C