Updated cpp.php

This commit is contained in:
2026-02-27 14:24:37 -06:00
parent 294f8c30f5
commit 950f199949
2 changed files with 25 additions and 1 deletions

Binary file not shown.

View File

@@ -343,7 +343,31 @@
<p>
A function is a wrapper to easily reuse code and improve readability of your program. The function signature contains the return type, the identifier of the function, and the parameters that the function requires. The function contains statements within the curly braces. Finally, the function returns a value which has a type indicated in the function signature. Proper functions also have one intended use. If a function contains more than one use, it is a good idea to split them up.
<code class="cblock"><pre>type name (parameters) {...}</pre></code>
Functions must be defined before they are called. That is, the definition must come before any reference to using the function. A function call is done by referencing the name of the function as a statement. For example <code>my_function(1,2,3);</code> is a call to <code>my_function(int a, int b, int c) {...}</code> with the parameter values <code>a = 1, b = 2, c = 3</code>.
Functions must be defined before they are called. That is, the definition must come before any reference to using the function. A function call is done by referencing the name of the function as a statement. For example <code>my_function(1,2,3);</code> is a call to <code>my_function(int a, int b, int c) {...}</code> with the parameter values <code>a = 1, b = 2, c = 3</code>.<br>
<br>
A function which does not return anything has the type of <code>void</code>. When using a void type for a function, it is okay to omit the return statement at the end of the function. In other words, when using a void type, the return statement is optional.<br>
<br>
Functions are also essential to organized code. It can also save you time because you no longer need to rewrite or copy large blocks of code that may need to be re-used. Instead, just call the function.
</p>
<h3 id="functions_types">II. Function Types</h3>
<p>
In c++, there are three different types of function parameters.
<ul>
<li>Pass by value</li>
<ul>
<li>The data that is included in the function parameter is copied from the value of the variable that is in the argument. This creates an entirely new variable with the exact same data as the variable in the parameter. This new variable has only the scope of the function it is used in. When the function exists, this variable is destroyed.</li>
</ul>
<li>Pass by reference</li>
<ul>
<li></li>
</ul>
<li>Constant parameters</li>
<ul>
<li></li>
</ul>
</ul>
<h4>Pass by value:</h4>
</p>
<h2 id="other">Other Topics</h2>
<h3 id="other_string-manipulation">String Manipulation</h3>