← BYTES
Go·Starter·Ref: 10.1.17
Why might a Go function be written as `func divide(a, b int) (int, error)`, returning two values?
Have a question about this video? Mention reference 10.1.17 when you contact us.
a.Go functions are required to always return exactly two values
b.It's returning both the successful result and an error value, following Go's idiomatic convention of signaling failure via an explicit error return rather than exceptions
c.The second value is always ignored by callers and exists only for documentation
d.It's a leftover legacy feature with no modern use
Multiple return values are a core Go feature, and the (result, error) pairing is the language's standard idiom for fallible operations -- the caller inspects the error return to decide whether the result is meaningful, instead of relying on thrown exceptions as in many other languages.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES10117#Go