Passing values vs pointers
📖 Scenario: Imagine you have a simple program that manages a person's age. You want to understand how changing the age inside a function affects the original age variable. This will help you learn the difference between passing values and passing pointers in Go.
🎯 Goal: You will create a program that shows how passing a value to a function does not change the original variable, but passing a pointer to a function allows you to change the original variable.
📋 What You'll Learn
Create a variable
age with the value 30Create a function
increaseAgeValue that takes an int parameter and increases it by 1Create a function
increaseAgePointer that takes a pointer to an int and increases the value it points to by 1Call both functions with the
age variable and observe the differencePrint the value of
age after each function call💡 Why This Matters
🌍 Real World
Understanding passing by value and by pointer helps when writing programs that manage data efficiently, like updating user profiles or handling large data structures.
💼 Career
Many Go programming jobs require knowledge of pointers to write efficient and correct code, especially in system programming, backend services, and performance-critical applications.
Progress0 / 4 steps