Nearby lessons

56 of 72

C - Passing Pointers to Functions

Learn how to pass a variable's address to a function so the function can change the original value.

Why Pass a Pointer to a Function?

When a normal value is passed to a function, the function receives a copy. If you pass the variable's address, the function can use a pointer to change the original variable.

Example01
Loading editor…

Swap Two Numbers Using Pointers

This function swaps the original values because it receives their addresses.

Example02
Loading editor…

Remember

  • Use &number when calling the function to pass the address.
  • Use a pointer parameter such as int *ptr.
  • Use *ptr to access or change the original value.

In C, this is often called call by reference in beginner lessons, but technically the address is passed by value.

📝 Key Takeaways
  • C passes function arguments by value.
  • Passing an address lets a function access the original variable.
  • Use * inside the function to change the value at that address.

🧠 Test Your Knowledge

1 Questions
Progress: 0 / 1

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.