Golang function parameters

Why we dont use var keyword in function parameters in golang?

Hi @Ash ,

Welcome to the forum.

Why do you expect that the var keyword can/shall be used inside function parameters?
What benefit would the var keyword have in function parameter lists?

Coz i think that var is something that indicates that it can change its value,so a function parameter might change its value while the function is being executed… Iam probably getting it completely wrong.

In Go all parameters are passed by Value. Does no exists the concept “pass by reference”.so you have to pass a pointer to have the “var” behaviour you are mentioning

I mean in golang var keyword is used to declare a variable of any type,so aren’t function parameters variables… Why we avoid using var keyword in function parameter?

func do (a, b int)

This is fine.

But this one is not

func do (var a int, var b int)

Maybe because function parameters are always variables. They can’t be const, so there’s no need for extra annotation.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.