O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Passing by Value

Passing by value simply means that the actual value is passed as if it were a constant. The variable is treated as a constant inside the function. If any changes are made, they will not be persistent, and it is bad programming practice to alter a variable that has been passed by value.

Bear in mind that the code inside the function is executing in isolation. Hence, you might not know whether the calling code specified a variable or constant in the call itself, and so this logic affects the way that the variable is treated inside the function body.

Consider the following function:

int AddTwoValues ( int nOne, int nTwo )
{
  return nOne + nTwo;
}

nOne and nTwo are local to the AddTwoValues function. You can call the function in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required