Chapter 43: Parameters Arguments

parameters vs arguments (also called: formal parameters vs actual arguments / parameters vs arguments)

This distinction trips up almost everyone coming from Python, JavaScript, Java or C++ at first — because Go is extremely explicit and strict about types and naming.

Let me explain it like we’re sitting together with VS Code open, writing small functions, calling them, and discussing every detail slowly and clearly.

1. The Two Sides of the Coin – Quick Definitions

Term Where it lives Meaning Also called Example in code
Parameter Inside the function definition The placeholder name and type the function expects to receive Formal parameter func add(a int, b int) → a and b are parameters
Argument Outside — when calling the function The actual value you pass when you call the function Actual argument / value add(17, 25) → 17 and 25 are arguments

Very simple sentence to remember forever:

The function defines parameters You pass arguments to fill those parameters

2. Visual Example – Side by Side

Go

So:

  • a and b → parameters (they exist only inside the function definition)
  • 17 and 25 → arguments (they are the concrete values you give when calling)

3. Different Ways Parameters Are Declared in Go

Go has very clean and expressive syntax for parameters.

Style 1 – Full type every time

Go

Style 2 – Same-type parameters → list types once (very common)

Go

→ length float64, width float64 → shortened to length, width float64

Style 3 – No parameters

Go

Style 4 – Variadic parameters (…)

Go

→ only last parameter can be variadic → inside function it becomes a slice []int

4. How Arguments Are Passed (Very Important in Go)

Go uses pass-by-value — but for slices/maps/channels it’s cheap because you copy only the header (pointer + len + cap).

Go

Key takeaway:

  • Primitive types (int, string, bool, float64, struct, array) → full copy
  • Slice / map / channel / function / interface → only descriptor/header copied (very cheap)
  • If you want to modify the caller’s slice header (len/cap), use pointer: func modifySlice(s *[]int)

5. Named Parameters? (No – Go has none)

Go has no named arguments like Python (func(a=1, b=2)). Arguments must be passed in the exact order of parameters.

Go

6. Real-World Patterns You Will Use Every Day

Go

7. Your Quick Practice – Try Writing These

  1. Function greet(name string, age int) that prints personalized message
  2. Function max(a, b int) int – returns larger number
  3. Variadic function join(separator string, words …string) string → like strings.Join but you write it yourself
  4. Function swap(x, y *int) that swaps two integers using pointers

Which one was easiest / most fun?

Any part still confusing?

  • Why pass-by-value + cheap slice header is actually good?
  • Why no named parameters / keyword arguments in Go?
  • Variadic vs slice parameter – when to choose which?
  • Or ready for return types / multiple returns in more depth next?

Keep writing and calling small functions — this is the moment where you go from “learning syntax” to “building real logic”.

You’re doing really great — keep asking! 💪🇮🇳🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *