Array Parameter Example (ALWAYS pass by reference)

Raheelanjum
2 min read3 days ago

Arrays are always passed by reference in C. They do not use the '&' notation but are passed by reference nonetheless. For example:

Constant Reference

To protect from accidentally changing a reference parameter when we really want it not to be changed (we just want to save time/memory), we can use the C keyword const. For example:

Void Functions

If a function does not return a value, then a special "TYPE" is used to tell the computer this. The return type is "void" (all lower case).

Void functions are mostly used in two classes of functions.

The first is a function that prints information for the user to read. For example (for our purposes), the printf function is treated as a void function. (In actuality, printf returns an integer, which is the number of characters printed... but we almost always ignore this value.)

The second use of void functions is with "reference" parameters (e.g., arrays). A reference parameter is not a copy of the input data, as is so often the case. A reference parameter is an "alias" for the same bucket in memory as the input data. Thus any change made to a reference parameter is in fact made to the original variable!

--

--

Raheelanjum
Raheelanjum

Written by Raheelanjum

Highly skilled and experienced content writer dedicated to crafting compelling, informative content that resonates with diverse audiences. Expertise spans blog

Responses (14)