Created: 2023-01-12 20:39
Status: #concept
Subject: Programming
Tags: C Function

Pass-by-Reference

Refers to the action of passing a Function argument through its Memory Address instead of Pass-By-Value.

It is required in order for the function to manipulate the argument within its Local Scope.

C Syntax

We have to indicate a Function takes in a Pointer Parameter by prepending a * to the parameter Variable name.

We then have to pass a Memory Address argument through the Address Operator &var or a Pointer Variable p into the Function call.

C decmpose() Function.png

const Function Parameter Modifier

Prepending const to a Function Pointer Parameter will allow us to do Pass-by-Reference, BUT NOT LET US MODIFY THE ORIGINAL VARIABLE'S VALUE.

Adding const makes a data type Constant and won't change during program execution.

const Parameters with Pointers Example.png

References