Search⌘ K
AI Features

Issues in the Pass by Value

Explore the drawbacks of using pass by value in C functions, including the inability to propagate changes back to the caller and the inefficiency caused by copying large amounts of data. Understand scenarios where pass by value leads to performance issues and why pass by reference or pointers are better alternatives for sharing memory efficiently between functions.

Introduction

Pass by value is neat and easy! It does the job perfectly if we need to pass some information for the called function to read.

Pass by value works by creating copies of the arguments and then passing those copies to the called function.

Having to create a copy introduces two drawbacks. We will discuss them now.

Changing the arguments

The first drawback is that we can not propagate the changes from the called function (callee) to the caller. We already saw this in the previous lesson.

Too many copies

The second drawback is more subtle. Even if the code works fine, it may not be ...