{"id":31433,"date":"2025-02-04T10:07:40","date_gmt":"2025-02-04T10:07:40","guid":{"rendered":"http:\/\/toposuranos.com\/material\/?p=31433"},"modified":"2025-02-24T11:00:46","modified_gmt":"2025-02-24T11:00:46","slug":"functions-in-c","status":"publish","type":"post","link":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/","title":{"rendered":"Functions in C++"},"content":{"rendered":"<p><head><title>Functions in C++<\/title><\/p>\n<style>\n        p, ul, ol {\n            text-align: justify;\n        }\n        h1, h2 {\n            text-align: center;\n        }<\/p>\n<p>table {\n        width: 100%;\n        border-collapse: collapse;\n        margin: 20px 0;\n        font-size: 18px;\n        text-align: left;\n    }\n    th, td {\n        padding: 12px;\n        border: 1px solid #ddd;\n    }\n    th {\n        background-color: #007BFF;\n        color: white;\n        text-align: center;\n    }\n    tr:nth-child(even) {\n        background-color: #f2f2f2;\n    }\n    tr:hover {\n        background-color: #ddd;\n    }\n    <\/style>\n<p><\/head><body><\/p>\n<header>\n<h1>Functions in C++: The Key Piece for Writing Clear and Reusable Code<\/h1>\n<p><em>Have you noticed that as a program grows, its code becomes harder to understand and maintain? If you have ever felt that your code looks like a tangled labyrinth, it is because you are not yet fully leveraging functions in C++. These act as building blocks that allow you to break a program into manageable parts, making it easier to read, maintain, and optimize. In this lesson, you will learn how to use them effectively to improve your code organization, write more structured programs, and make your C++ development more professional and efficient.<\/em><\/p>\n<\/header>\n<section>\n<h2>Learning Objectives<\/h2>\n<p style=\"text-align:center;\">By the end of this lesson, you will have learned to:<\/p>\n<ul>\n<li><strong>Understand<\/strong> the purpose of functions and why they are essential in C++.<\/li>\n<li><strong>Create<\/strong> functions correctly, ensuring structured code.<\/li>\n<li><strong>Invoke<\/strong> functions within a program and understand how they execute.<\/li>\n<li><strong>Distinguish<\/strong> between functions that return values and those that simply execute instructions.<\/li>\n<li><strong>Compare<\/strong> different ways to define functions and choose the best approach depending on the situation.<\/li>\n<\/ul>\n<\/section>\n<p style=\"text-align:center;\">\n<strong><u>CONTENT INDEX<\/u><\/strong><br \/>\n<a href=\"#1\">Declaration, Invocation, and Definition of Functions<\/a><br \/>\n<a href=\"#2\">Approach: Declare \u2013 Invoke \u2013 Define<\/a><br \/>\n<a href=\"#3\">Approach: Declare and Implement Before Invoking<\/a><br \/>\n<a href=\"#4\">Return Value Propagation<\/a><br \/>\n<a href=\"#5\">Recursion: Functions That Call Themselves<\/a><br \/>\n<a href=\"#6\">Multiple Return in Functions<\/a><br \/>\n<a href=\"#7\">Function Overloading<\/a><br \/>\n<a href=\"#8\">Inline Functions in C++<\/a><br \/>\n<a href=\"#9\">Final Reflection on Functions in C++<\/a><\/p>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/1SeIwMqpXgM?si=vYxfnmqmkLyXeaY9\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"1\"><\/a><\/p>\n<h2>Function Declaration, Invocation, and Definition<\/h2>\n<p>\nIn C++, functions are reusable blocks of code that allow structuring a program in a modular and organized way. Each function encapsulates a specific task, which helps improve code clarity and maintainability. To use a function in a program, we must follow three fundamental steps: <strong>declaration, invocation, and definition.<\/strong>\n<\/p>\n<p>These three concepts are essential, and each serves a particular purpose in the code structure. Let&#8217;s examine each one in detail.<\/p>\n<ol>\n<li><strong>Function Declaration<\/strong>\n<p>Before a function can be used in the code, the compiler must be informed of its existence. This is done through a <strong>function declaration or prototype.<\/strong><\/p>\n<p>The function declaration tells the compiler three fundamental things:<\/p>\n<ul>\n<li><strong>The data type that the function will return<\/strong> (or <code>void<\/code> if it returns nothing).<\/li>\n<li><strong>The function&#8217;s name.<\/strong><\/li>\n<li><strong>The parameters it accepts<\/strong> (if any), along with their types.<\/li>\n<\/ul>\n<p><\/p>\n<p>The general syntax for a function declaration is:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">return_type function_name (parameter_list);\r\n<\/pre>\n<p>The function declaration is usually placed before <code>main()<\/code> or in a header file (.h) when working with multiple files.<\/p>\n<\/li>\n<li><strong>Function Invocation<\/strong>\n<p>After declaring a function, we can invoke it, meaning we call it within the code so it executes.<\/p>\n<p>When a function is invoked:<\/p>\n<ul>\n<li>The code within its definition is executed.<\/li>\n<li>If the function returns a value, it can be stored in a variable or used directly in an expression.<\/li>\n<li>If the function is of type <code>void<\/code>, it simply executes its instructions without returning anything.<\/li>\n<\/ul>\n<p><\/p>\n<p>The syntax for invoking a function is simply writing its name followed by parentheses with arguments (if needed):<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nfunction_name(arguments);\r\n<\/pre>\n<\/li>\n<li><strong>Function Definition<\/strong>\n<p>Finally, the function definition is the part where its behavior is implemented. Here, the instructions that will be executed when the function is invoked are specified.<\/p>\n<p>The general syntax for a function definition is:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nreturn_type function_name (parameter_list) {\r\n    \/\/ Function body: instructions to execute\r\n    return value; \/\/ (if the function returns a value)\r\n}\r\n<\/pre>\n<p>Each function definition must follow these rules:<\/p>\n<ul>\n<li>It must match the declaration (if previously declared).<\/li>\n<li>If the function returns a value (e.g., <code>int<\/code>), it must include a <code>return<\/code> statement with the value to return.<\/li>\n<li>If the function does not return anything (<code>void<\/code>), it simply executes its instructions and does not need a <code>return<\/code> statement.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Execution Flow<\/h3>\n<p>When the program runs, functions are called in the order they appear in <code>main()<\/code>. The execution flow is as follows:<\/p>\n<ol>\n<li>The compiler recognizes the function declaration.<\/li>\n<li>In <code>main()<\/code>, when a function call is encountered, the program control is transferred to the function definition.<\/li>\n<li>The function executes its instructions.<\/li>\n<li>If the function has a return value, it is returned to the line where it was called.<\/li>\n<li>The program flow returns to <code>main()<\/code> or to the function that made the call.<\/li>\n<\/ol>\n<h3>Importance of Prior Declaration<\/h3>\n<p>Declaring functions before using them is crucial because the C++ compiler processes the code from top to bottom. If we try to call a function before it has been defined or declared, we will get an error.<\/p>\n<p>There are two main ways to handle this:<\/p>\n<ol>\n<li>Declare the function before <code>main()<\/code> and define it afterward (as we have seen so far).<\/li>\n<li>Define the function before <code>main()<\/code>, avoiding the need for a prior declaration.<\/li>\n<\/ol>\n<p>Both approaches are valid, but the first is more useful in large programs where functions are in different files.<\/p>\n<\/section>\n<section><a name=\"2\"><\/a><\/p>\n<h2>Approach: Declare &#8211; Invoke &#8211; Define<\/h2>\n<p>One of the most commonly used approaches for structuring functions in C++ is <strong>declare &#8211; invoke &#8211; define.<\/strong> Following this logic, we organize our code into three fundamental stages:<\/p>\n<ol>\n<li><strong>Declaration:<\/strong> The compiler is informed about the existence of the function before its use, specifying its name, return type, and parameters (if any).<\/li>\n<li><strong>Invocation:<\/strong> The function is called within the main code (<code>main()<\/code> in most cases), executing its content.<\/li>\n<li><strong>Definition:<\/strong> The function&#8217;s implementation is specified, detailing the instructions it will execute when invoked.<\/li>\n<\/ol>\n<p>This structure improves code organization, making maintenance and scalability easier. Let&#8217;s review an example where we apply this approach:<\/p>\n<h3>Example: <code>consoledisplay()<\/code> Function<\/h3>\n<p>In the following code, we follow the <strong>declare &#8211; invoke &#8211; define<\/strong> sequence:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/\/ First, we declare the function\r\nvoid consoledisplay();\r\n\r\nint main() {\r\n    \/\/ We invoke the function\r\n    consoledisplay();\r\n    return 0;\r\n}\r\n\r\n\/\/ We define the previously declared function, detailing its internal behavior\r\nvoid consoledisplay() {\r\n    cout &lt;&lt; &quot;This is a simple string of characters or literals.&quot; &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Now I show you the number five. Here it is: &quot; &lt;&lt; 5 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Let&#039;s see what result we get if we do 10\/5. The result is: &quot; &lt;&lt; 10\/5 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;A typical way to approximate the number Pi is by doing 22\/7. The result is: &quot; &lt;&lt; 22\/7 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;In C++, writing 22\/7 is not the same as 22.0\/7, the treatment is different.&quot; &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;With this simple change, we can see that 22.0\/7 equals &quot; &lt;&lt; 22.0\/7 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Doesn&#039;t this seem like a better approximation?&quot; &lt;&lt; endl;\r\n}\r\n<\/pre>\n<p>The expected output of this code is:<\/p>\n<p><code>This is a simple string of characters or literals.<br \/>\nNow I show you the number five. Here it is: 5<br \/>\nLet's see what result we get if we do 10\/5. The result is: 2<br \/>\nA typical way to approximate the number Pi is by doing 22\/7. The result is: 3<br \/>\nIn C++, writing 22\/7 is not the same as 22.0\/7, the treatment is different.<br \/>\nWith this simple change, we can see that 22.0\/7 equals 3.14286<br \/>\nDoesn't this seem like a better approximation?<\/code><\/p>\n<p>To better understand the declare &#8211; invoke &#8211; define approach, let&#8217;s focus on three key parts of the code:<\/p>\n<ol>\n<li><strong>Line 5: Function Declaration<\/strong>\n<ul>\n<li><code>void consoledisplay();<\/code> informs the compiler that at some point in the code, a function called <code>consoledisplay()<\/code> will exist.<\/li>\n<li>It specifies that its return type is <code>void<\/code>, meaning it will not return any value.<\/li>\n<li>Although the implementation of <code>consoledisplay()<\/code> is not yet known, this declaration allows the compiler to recognize it when used later.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Line 9: Function Invocation<\/strong>\n<ul>\n<li>Inside the <code>main()<\/code> function, the line <code>consoledisplay();<\/code> executes the function.<\/li>\n<li>At this moment, the compiler already recognizes the existence of <code>consoledisplay()<\/code> thanks to its prior declaration.<\/li>\n<li>When the function is invoked, program control is transferred to its definition, where its content is executed.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Lines 14 to 22: Function Definition<\/strong>\n<ul>\n<li>This is where the detailed implementation of <code>consoledisplay()<\/code> is found, specifying its instructions.<\/li>\n<li>In this case, the function prints several messages to the console, including numbers and mathematical operations.<\/li>\n<li>One important thing is the difference between <code>22\/7<\/code> and <code>22.0\/7<\/code>. When using <code>22\/7<\/code>, both numbers are integers, resulting in <code>3<\/code> due to integer division. However, when writing <code>22.0\/7<\/code>, the operation is forced into floating-point arithmetic, yielding <code>3.14286<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/section>\n<section><a name=\"3\"><\/a><\/p>\n<h2>Approach: Declare and Implement Before Invoking<\/h2>\n<p>In C++, besides the <strong>declare &#8211; invoke &#8211; define<\/strong> approach, there is another valid way to structure our functions: <strong>declare and implement before invoking.<\/strong> This method combines the declaration and definition in a single step, before the function is used in <code>main()<\/code>.<\/p>\n<p>In this approach, instead of making a prior declaration of the function and defining it after <code>main()<\/code>, we directly declare and define it in the same place before invoking it. This has the advantage of avoiding a separate declaration and making the code more compact and easier to read in small programs.<\/p>\n<p>The general structure of this approach is as follows:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/ Define the function before main()\r\nreturn_type function_name(parameter_list) {\r\n    \/\/ Function body\r\n    return value; \/\/ if necessary\r\n}\r\n\r\nint main() {\r\n    \/\/ Function invocation\r\n    function_name(arguments);\r\n}\r\n<\/pre>\n<p>Since it is defined before <code>main()<\/code>, the compiler already knows it when invoked, so a prior declaration is not necessary.<\/p>\n<h3><strong>Example: <code>consoledisplay()<\/code> Function Without Prior Declaration<\/strong><\/h3>\n<p>Now let&#8217;s see a practical example where we apply this approach:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/\/ Define the function before invoking it\r\nvoid consoledisplay() {\r\n    cout &lt;&lt; &quot;This is a simple string of characters or literals.&quot; &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Now I show you the number five. Here it is: &quot; &lt;&lt; 5 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Let&#039;s see what result we get if we do 10\/5. The result is: &quot; &lt;&lt; 10\/5 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;A typical way to approximate the number Pi is by doing 22\/7. The result is: &quot; &lt;&lt; 22\/7 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;In C++, writing 22\/7 is not the same as 22.0\/7, the treatment is different.&quot; &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;With this simple change, we can see that 22.0\/7 equals &quot; &lt;&lt; 22.0\/7 &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Doesn&#039;t this seem like a better approximation?&quot; &lt;&lt; endl;\r\n}\r\n\r\nint main() {\r\n    \/\/ Invoke the function\r\n    consoledisplay();\r\n    return 0;\r\n}\r\n<\/pre>\n<p>In this code, we can see that:<\/p>\n<ol>\n<li><strong>Between lines 5 and 13, declaration and definition are combined<\/strong>\n<p>The function <code>consoledisplay()<\/code> is defined directly before <code>main()<\/code>, without needing a separate declaration.<\/p>\n<\/li>\n<li><strong>On line 17, the function is invoked within <code>main()<\/code><\/strong>\n<p>Since the function has already been defined before, the compiler recognizes it and allows its execution without issues.<\/p>\n<\/li>\n<li><strong>The result is exactly the same<\/strong>\n<p>Functionally, this approach generates the same behavior as the declare &#8211; invoke &#8211; define approach, but with a more compact structure.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u2705 Advantages:<\/strong><\/p>\n<ul>\n<li>More direct and compact code in small programs.<\/li>\n<li>No need for a prior declaration, reducing the number of code lines.<\/li>\n<li>Easier readability in short scripts where all functions are in the same file.<\/li>\n<\/ul>\n<p><strong>\u274c Disadvantages:<\/strong><\/p>\n<ul>\n<li>In large programs, it can make organization difficult if there are many functions defined before <code>main()<\/code>.<\/li>\n<li>Less useful when working with multiple files (.h and .cpp), as it is preferable to keep the declaration in a separate file.<\/li>\n<\/ul>\n<\/section>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/AkIhpuZP80k?si=yT8732AKk2i-QBLe\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"4\"><\/a><\/p>\n<h2>Return Value Propagation<\/h2>\n<p>So far, we have worked with functions that simply execute instructions without returning any results. However, in many cases, a function needs to return a value so that it can be used in other calculations or stored in variables. This process is known as return value propagation.<\/p>\n<p>In this section, we will learn how functions that return values work, how they differ from <code>void<\/code> functions, and how we can take advantage of this mechanism in C++.<\/p>\n<h3>Practical Example: Function That Calculates the Area of a Rectangle<\/h3>\n<p>To illustrate return value propagation, we will implement a function that receives the base and height of a rectangle and calculates its area.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/\/ Function that calculates the area of a rectangle and returns the result\r\ndouble calculateArea(double base, double height) {\r\n    return base * height;\r\n}\r\n\r\nint main() {\r\n    double base, height;\r\n    \r\n    \/\/ Ask the user to enter the values\r\n    cout &lt;&lt; &quot;Enter the base of the rectangle: &quot;;\r\n    cin &gt;&gt; base;\r\n    cout &lt;&lt; &quot;Enter the height of the rectangle: &quot;;\r\n    cin &gt;&gt; height;\r\n\r\n    \/\/ Call the function and store its result\r\n    double area = calculateArea(base, height);\r\n\r\n    \/\/ Display the result\r\n    cout &lt;&lt; &quot;The area of the rectangle is: &quot; &lt;&lt; area &lt;&lt; endl;\r\n    \r\n    return 0;\r\n}\r\n<\/pre>\n<ol>\n<li><strong>The function <code>calculateArea()<\/code> returns a value<\/strong>\n<ul>\n<li>Receives two values (<code>base<\/code> and <code>height<\/code>) as parameters.<\/li>\n<li>Calculates the area using the multiplication <code>base * height<\/code>.<\/li>\n<li>Uses <code>return<\/code> to send the result of the operation back to the part of the program that invoked it.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Using the return value in <code>main()<\/code><\/strong>\n<ul>\n<li>The values of <code>base<\/code> and <code>height<\/code> are entered by the user.<\/li>\n<li>The function <code>calculateArea()<\/code> is called, and its result is stored in the variable <code>area<\/code>.<\/li>\n<li>Finally, the result is displayed in the console.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Key Difference from a <code>void<\/code> Function<\/strong>\n<p>If <code>calculateArea()<\/code> were of type <code>void<\/code>, we would have to display the result directly inside the function instead of returning it to <code>main()<\/code> for later use.<\/p>\n<\/li>\n<\/ol>\n<h3>Example: Function That Determines If a Number Is Even or Odd<\/h3>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nbool isEven(int number) {\r\n    return number % 2 == 0;\r\n}\r\n\r\nint main() {\r\n    int number;\r\n    cout &lt;&lt; &quot;Enter a number: &quot;; cin &gt;&gt; number;\r\n\r\n    if (isEven(number)) {\r\n        cout &lt;&lt; &quot;The number is even.&quot; &lt;&lt; endl;\r\n    } else {\r\n        cout &lt;&lt; &quot;The number is odd.&quot; &lt;&lt; endl;\r\n    }\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>Here, the function <code>isEven()<\/code> returns <code>true<\/code> if the number is even and <code>false<\/code> if it is odd, allowing <code>main()<\/code> to use the result to decide which message to display.<\/p>\n<\/section>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/cRi0T1AeVaA?si=zIcuFhfy5Xs9U_kn\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"5\"><\/a><\/p>\n<h2>Recursion: Functions That Call Themselves<\/h2>\n<p><strong>Recursion<\/strong> is a technique where a function calls itself to solve problems by breaking them down into smaller versions of themselves. It is particularly useful in algorithms such as factorial calculation, the Fibonacci series, and traversing data structures like trees.<\/p>\n<h3>Example: Factorial of a Number<\/h3>\n<p>The factorial of a number <span class=\"katex-eq\" data-katex-display=\"false\">n<\/span> is <span class=\"katex-eq\" data-katex-display=\"false\">n!=n\\cdot(n-1)\\cdot(n-2) \\cdots 3 \\cdot2 \\cdot 1<\/span>. This formulation has a recursive structure that we can mathematically represent as follows:<\/p>\n<p style=\"text-align:center;\"><span class=\"katex-eq\" data-katex-display=\"false\">\n\\begin{array}{rl}\n\n0! &amp;=1\\\\\n\nn! &amp;= n\\cdot(n-1)!\\\\\n\n\\end{array}\n\n<\/span>\n<p>With this in mind, we can program this function in C++ as follows:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n \r\nint factorial(int n) {\r\n    if (n == 0 || n == 1) {\r\n        return 1;\r\n    }\r\n    return n * factorial(n - 1);\r\n}\r\n \r\nint main() {\r\n    int number;\r\n    cout &lt;&lt; &quot;Enter a number: &quot;; cin &gt;&gt; number;\r\n    cout &lt;&lt; &quot;The factorial of &quot; &lt;&lt; number &lt;&lt; &quot; is &quot; &lt;&lt; factorial(number) &lt;&lt; endl;\r\n    return 0;\r\n}\r\n<\/pre>\n<p>In this code:<\/p>\n<ul>\n<li>The function <code>factorial(n)<\/code> calls itself with <code>n-1<\/code> until it reaches the base case (<code>n == 0<\/code> or <code>n == 1<\/code>).<\/li>\n<li>The function resolves recursively, multiplying the values until it finds the result.<\/li>\n<\/ul>\n<h3>Example: Fibonacci Numbers<\/h3>\n<p>The Fibonacci numbers are those included in the sequence <span class=\"katex-eq\" data-katex-display=\"false\">1, 1, 2, 3, 5, 8, 13, \\cdots<\/span>. This sequence is characterized by the fact that each number is equal to the sum of the previous two.<\/p>\n<p>Mathematically, if <span class=\"katex-eq\" data-katex-display=\"false\">fibo(n)<\/span> is the function whose results are the Fibonacci numbers, then it has the following mathematical structure:<\/p>\n<p style=\"text-align:center;\"><span class=\"katex-eq\" data-katex-display=\"false\">\n\\begin{array}{rl}\n\nfibo(0) &amp;= 1\\\\\n\nfibo(1) &amp;= 1 \\\\\n\nfibo(n) &amp;= fibo(n-1) + fibo(n-2)\n\n\\end{array}\n\n<\/span>\n<p>A C++ code example that displays Fibonacci numbers is the following:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n \r\nusing namespace std;\r\n \r\nint fibo(int number) {\r\n    if (number == 0 || number == 1) {\r\n        return 1;\r\n    }\r\n    return fibo(number - 1) + fibo(number - 2);\r\n}\r\n\r\nint main() {\r\n    int x = 0, i = 0;\r\n    cout &lt;&lt; &quot;Enter a number: &quot;; cin &gt;&gt; x;\r\n     \r\n    while (i &lt; x) {\r\n        cout &lt;&lt; &quot;The Fibonacci number at position &quot; &lt;&lt; i + 1 &lt;&lt; &quot; is: &quot; &lt;&lt; fibo(i) &lt;&lt; endl;\r\n        i = i + 1;\r\n    }   \r\n}\r\n<\/pre>\n<\/section>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/EnMxDCHV1qg?si=4Y6oVAdNe9UeVDL5\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"6\"><\/a><\/p>\n<h2>Multiple Return Values in Functions<\/h2>\n<p>In C++, a function can return more than one value using structures such as <code>std::pair<\/code>, <code>std::tuple<\/code>, or references to variables.<\/p>\n<h3>Example: Function That Returns Two Values Using <code>std::pair<\/code><\/h3>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;utility&gt; \/\/ To use std::pair\r\nusing namespace std;\r\n \r\npair&lt;int, int&gt; divide(int a, int b) {\r\n    return make_pair(a \/ b, a % b);\r\n}\r\n \r\nint main() {\r\n    int numerator = 0, denominator = 1;\r\n     \r\n    cout &lt;&lt; &quot;Enter the numerator: &quot;; cin &gt;&gt; numerator;\r\n    cout &lt;&lt; &quot;Enter the denominator: &quot;; cin &gt;&gt; denominator;\r\n     \r\n    pair&lt;int, int&gt; result = divide(numerator, denominator);\r\n \r\n    cout &lt;&lt; &quot;Quotient: &quot; &lt;&lt; result.first &lt;&lt; endl;\r\n    cout &lt;&lt; &quot;Remainder: &quot; &lt;&lt; result.second &lt;&lt; endl;\r\n \r\n    return 0;\r\n}\r\n<\/pre>\n<p>Here, the function <code>divide()<\/code> returns two values: the quotient and the remainder of an integer division.<\/p>\n<h3>Example: Function That Returns Multiple Values Using <code>std::tuple<\/code><\/h3>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;tuple&gt;\r\nusing namespace std;\r\n\r\ntuple&lt;int, int, int&gt; operations(int a, int b) {\r\n    return make_tuple(a + b, a - b, a * b);\r\n}\r\n\r\nint main() {\r\n    int sum = 0, difference = 0, product = 0;\r\n    int a = 0, b = 0;\r\n    \r\n    cout &lt;&lt; &quot;Enter a number: &quot;; cin &gt;&gt; a;\r\n    \r\n    cout &lt;&lt; &quot;Enter another number: &quot;; cin &gt;&gt; b;\r\n    \r\n    std::tie(sum, difference, product) = operations(a, b);\r\n\r\n    cout &lt;&lt; &quot;Sum: &quot; &lt;&lt; sum &lt;&lt; &quot;, Difference: &quot; &lt;&lt; difference &lt;&lt; &quot;, Product: &quot; &lt;&lt; product &lt;&lt; endl;\r\n    return 0;\r\n}\r\n<\/pre>\n<\/section>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/UdkBf26gTew?si=RTadJpxFBQ2Uctzs\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"7\"><\/a><\/p>\n<h2>Function Overloading<\/h2>\n<p>Function overloading allows defining multiple functions with the same name but different types or numbers of parameters. This improves code readability and reusability.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;string&gt; \/\/ Required to use std::string\r\n#include &lt;cmath&gt;\r\n\r\nusing namespace std;\r\n\r\n\/\/ Area of a square or circle (shapes with one parameter)\r\ndouble area(double side) {\r\n    return side * side;\r\n}\r\n\r\n\/\/ Area of a rectangle (or shapes with two parameters)\r\ndouble area(double base, double height) {\r\n    return base * height;\r\n}\r\n\r\n\/\/ Area of a triangle (or shapes with three parameters)\r\ndouble area(double a, double b, double c) {\r\n    return 0.25 * sqrt((a + b + c) * (a + b - c) * (a - b + c) * (-a + b + c));\r\n}\r\n\r\nint main() {\r\n    string shape;\r\n    double result = 0;\r\n    double l1 = 0, l2 = 0, l3 = 0;\r\n\r\n    \/\/ Ask for the shape\r\n    cout &lt;&lt; &quot;What shape is it? (square, circle, rectangle, or triangle): &quot;;\r\n    cin &gt;&gt; shape;\r\n\r\n    \/\/ Evaluate the shape using if-else\r\n    if (shape == &quot;square&quot;) {\r\n        cout &lt;&lt; &quot;How long is its side? &quot;; cin &gt;&gt; l1;\r\n        result = area(l1);\r\n        cout &lt;&lt; &quot;The area of the square is: &quot; &lt;&lt; result &lt;&lt; endl;\r\n    } \r\n    else if (shape == &quot;rectangle&quot;) {\r\n        cout &lt;&lt; &quot;How long is the base? &quot;; cin &gt;&gt; l1;\r\n        cout &lt;&lt; &quot;How long is the height? &quot;; cin &gt;&gt; l2;\r\n        result = area(l1, l2);\r\n        cout &lt;&lt; &quot;The area of the rectangle is: &quot; &lt;&lt; result &lt;&lt; endl;\r\n    } \r\n    else if (shape == &quot;circle&quot;) {\r\n        l1 = 3.141592653;\r\n        cout &lt;&lt; &quot;How long is the radius? &quot;; cin &gt;&gt; l2;\r\n        result = area(l1, l2);\r\n        cout &lt;&lt; &quot;The area of the circle is: &quot; &lt;&lt; result &lt;&lt; endl;\r\n    } \r\n    else if (shape == &quot;triangle&quot;) {\r\n        cout &lt;&lt; &quot;How long are its sides?&quot; &lt;&lt; endl;\r\n        cout &lt;&lt; &quot;Side 1: &quot;; cin &gt;&gt; l1;\r\n        cout &lt;&lt; &quot;Side 2: &quot;; cin &gt;&gt; l2;\r\n        cout &lt;&lt; &quot;Side 3: &quot;; cin &gt;&gt; l3;\r\n            \r\n        if ((l1 + l2 + l3) * (l1 + l2 - l3) * (l1 - l2 + l3) * (-l1 + l2 + l3) &lt; 0) {\r\n            cout &lt;&lt; &quot;The triangle is impossible&quot;;\r\n        }    \r\n        else {\r\n            result = area(l1, l2, l3);\r\n            cout &lt;&lt; &quot;The area of the triangle is: &quot; &lt;&lt; result &lt;&lt; endl;\r\n        }             \r\n    }\r\n    else {\r\n        cout &lt;&lt; &quot;Invalid shape.&quot; &lt;&lt; endl;\r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n<\/section>\n<p><center><iframe class=\"lazyload\" width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/0vzQFAXjqbg?si=ckRolBE3n0I5QPPp\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/center><\/p>\n<section><a name=\"8\"><\/a><\/p>\n<h2>Inline Functions in C++<\/h2>\n<p>Inline functions in C++ provide a mechanism to optimize program performance by reducing function call overhead. Instead of executing a conventional call, the compiler attempts to expand the function&#8217;s code directly in every place where it is invoked.<\/p>\n<h3>Syntax of an Inline Function<\/h3>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ninline return_type function_name(parameter_list) {\r\n    \/\/ Function body\r\n    return value; \/\/ If necessary\r\n}\r\n<\/pre>\n<p>By using <code>inline<\/code>, we eliminate the need to jump to another memory address to execute the function, which can reduce execution time.<\/p>\n<h3>Differences Between an Inline Function and a Conventional Function<\/h3>\n<table>\n<tr>\n<th style=\"width: 20%;\"><strong>Feature<\/strong><\/th>\n<th><strong>Conventional Function<\/strong><\/th>\n<th><strong>Inline Function<\/strong><\/th>\n<\/tr>\n<tr>\n<td><strong>Function Call<\/strong><\/td>\n<td>A call with execution jump is performed.<\/td>\n<td>The code is copied directly where it is used.<\/td>\n<\/tr>\n<tr>\n<td><strong>Execution Time<\/strong><\/td>\n<td>Can be slower due to function call overhead.<\/td>\n<td>Can be faster in small functions.<\/td>\n<\/tr>\n<tr>\n<td><strong>Memory Usage<\/strong><\/td>\n<td>A single copy of the function is stored in memory.<\/td>\n<td>Can increase binary size if the function is used many times.<\/td>\n<\/tr>\n<\/table>\n<h3>Example of an <code>inline<\/code> Function<\/h3>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\ninline int square(int x) {\r\n    return x * x;\r\n}\r\n\r\nint main() {\r\n    cout &lt;&lt; &quot;The square of 5 is: &quot; &lt;&lt; square(5) &lt;&lt; endl;\r\n    return 0;\r\n}\r\n<\/pre>\n<p><strong>\ud83d\udd0d Compiler Process:<\/strong><\/p>\n<ol>\n<li>The compiler replaces the call <code>square(5)<\/code> directly with <code>5 * 5<\/code>.<\/li>\n<li>There is no execution jump.<\/li>\n<li>The calculation is performed in the same line where the function was invoked.<\/li>\n<\/ol>\n<h3>Advantages and Disadvantages of <code>inline<\/code><\/h3>\n<p><strong>\u2705 Advantages<\/strong><\/p>\n<ul>\n<li><strong>Eliminates function call overhead:<\/strong> Reduces execution time in short and frequently called functions.<\/li>\n<li><strong>Facilitates compiler optimization:<\/strong> Can improve performance by avoiding CPU register and stack usage.<\/li>\n<li><strong>Ensures function code is available at compile time.<\/strong><\/li>\n<\/ul>\n<p><strong>\u274c Disadvantages<\/strong><\/p>\n<ul>\n<li><strong>Increases binary size:<\/strong> If the <code>inline<\/code> function is used many times in a large program, the code will be duplicated at every invocation point. This happens when used in long or highly repeated functions in the code.<\/li>\n<li><strong>Does not always guarantee inline expansion:<\/strong> The compiler may ignore the <code>inline<\/code> request if it deems it non-optimal.<\/li>\n<\/ul>\n<\/section>\n<footer><a name=\"9\"><\/a><\/p>\n<h2>Final Reflection on Functions in C++<\/h2>\n<p>Functions in C++ are an essential tool for writing modular, reusable, and maintainable code. Throughout this lesson, we have explored everything from the basics of declaration, invocation, and definition to more advanced techniques such as return value propagation, recursion, function overloading, and the use of <code>inline<\/code> functions. We have also compared different strategies for organizing code and how to choose the best one depending on the context.<\/p>\n<p>Understanding and correctly applying functions will not only make your code clearer and more efficient but also allow you to tackle more complex problems with well-structured solutions. Now you have the foundation to develop C++ programs with a more professional and scalable approach. The best way to reinforce these concepts is through practice, so I encourage you to experiment with different types of functions and apply them in your own projects. Keep exploring and taking your C++ skills to the next level!<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Functions in C++ Functions in C++: The Key Piece for Writing Clear and Reusable Code Have you noticed that as a program grows, its code becomes harder to understand and maintain? If you have ever felt that your code looks like a tangled labyrinth, it is because you are not yet fully leveraging functions in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":31365,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4,"footnotes":""},"categories":[975,993],"tags":[],"class_list":["post-31433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computing-and-informatics","category-programming-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Functions in C++ - toposuranos.com\/material<\/title>\n<meta name=\"description\" content=\"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Functions in C++\" \/>\n<meta property=\"og:description\" content=\"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"toposuranos.com\/material\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/groups\/toposuranos\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-04T10:07:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-24T11:00:46+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c-1024x585.jpg\" \/>\n<meta name=\"author\" content=\"giorgio.reveco\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Functions in C++\" \/>\n<meta name=\"twitter:description\" content=\"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.\" \/>\n<meta name=\"twitter:image\" content=\"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg\" \/>\n<meta name=\"twitter:creator\" content=\"@topuranos\" \/>\n<meta name=\"twitter:site\" content=\"@topuranos\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"giorgio.reveco\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/\"},\"author\":{\"name\":\"giorgio.reveco\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#\\\/schema\\\/person\\\/e15164361c3f9a2a02cf6c234cf7fdc1\"},\"headline\":\"Functions in C++\",\"datePublished\":\"2025-02-04T10:07:40+00:00\",\"dateModified\":\"2025-02-24T11:00:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/\"},\"wordCount\":3635,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#organization\"},\"image\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/funciones-en-c.jpg\",\"articleSection\":[\"Computing and Informatics\",\"Programming in C++\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/\",\"name\":\"Functions in C++ - toposuranos.com\\\/material\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/funciones-en-c.jpg\",\"datePublished\":\"2025-02-04T10:07:40+00:00\",\"dateModified\":\"2025-02-24T11:00:46+00:00\",\"description\":\"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#primaryimage\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/funciones-en-c.jpg\",\"contentUrl\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/funciones-en-c.jpg\",\"width\":1792,\"height\":1024,\"caption\":\"toposuranos.com\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/en\\\/functions-in-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/es\\\/cursos-de-matematica-y-fisica\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Functions in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#website\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/\",\"name\":\"toposuranos.com\\\/material\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#organization\",\"name\":\"toposuranos.com\\\/material\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/logo.png\",\"contentUrl\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/logo.png\",\"width\":2400,\"height\":2059,\"caption\":\"toposuranos.com\\\/material\"},\"image\":{\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/groups\\\/toposuranos\",\"https:\\\/\\\/x.com\\\/topuranos\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UC16yDm12cPcrwsE0fAM7X1g\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/69429190\"]},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/#\\\/schema\\\/person\\\/e15164361c3f9a2a02cf6c234cf7fdc1\",\"name\":\"giorgio.reveco\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/1694478625378-96x96.jpeg\",\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/1694478625378-96x96.jpeg\",\"contentUrl\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/1694478625378-96x96.jpeg\",\"caption\":\"giorgio.reveco\"},\"description\":\"Soy Licenciado en F\u00edsica, Magister en Ingenier\u00eda Industrial y Docente Universitario. Me dedico a desmitificar la f\u00edsica y las matem\u00e1ticas. Mi objetivo es hacer que estos campos sean f\u00e1cilmente comprensibles para todos, proporcionando las herramientas para explorar no solo el mundo que nos rodea, sino tambi\u00e9n las profundidades de nuestra propia existencia y el orden natural que nos conecta con el cosmos.\",\"sameAs\":[\"http:\\\/\\\/toposuranos.com\\\/material\"],\"url\":\"http:\\\/\\\/toposuranos.com\\\/material\\\/author\\\/giorgio-reveco\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Functions in C++ - toposuranos.com\/material","description":"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/","og_locale":"es_ES","og_type":"article","og_title":"Functions in C++","og_description":"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.","og_url":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/","og_site_name":"toposuranos.com\/material","article_publisher":"https:\/\/www.facebook.com\/groups\/toposuranos","article_published_time":"2025-02-04T10:07:40+00:00","article_modified_time":"2025-02-24T11:00:46+00:00","og_image":[{"url":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c-1024x585.jpg","type":"","width":"","height":""}],"author":"giorgio.reveco","twitter_card":"summary_large_image","twitter_title":"Functions in C++","twitter_description":"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.","twitter_image":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg","twitter_creator":"@topuranos","twitter_site":"@topuranos","twitter_misc":{"Escrito por":"giorgio.reveco","Tiempo de lectura":"14 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#article","isPartOf":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/"},"author":{"name":"giorgio.reveco","@id":"http:\/\/toposuranos.com\/material\/#\/schema\/person\/e15164361c3f9a2a02cf6c234cf7fdc1"},"headline":"Functions in C++","datePublished":"2025-02-04T10:07:40+00:00","dateModified":"2025-02-24T11:00:46+00:00","mainEntityOfPage":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/"},"wordCount":3635,"commentCount":0,"publisher":{"@id":"http:\/\/toposuranos.com\/material\/#organization"},"image":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#primaryimage"},"thumbnailUrl":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg","articleSection":["Computing and Informatics","Programming in C++"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/","url":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/","name":"Functions in C++ - toposuranos.com\/material","isPartOf":{"@id":"http:\/\/toposuranos.com\/material\/#website"},"primaryImageOfPage":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#primaryimage"},"image":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#primaryimage"},"thumbnailUrl":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg","datePublished":"2025-02-04T10:07:40+00:00","dateModified":"2025-02-24T11:00:46+00:00","description":"Learn to use functions in C++ efficiently, to declare, invoke, and define functions with practical examples, exploring concepts such as return values, overloading, recursion, and inline functions.","breadcrumb":{"@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["http:\/\/toposuranos.com\/material\/en\/functions-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#primaryimage","url":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg","contentUrl":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2025\/02\/funciones-en-c.jpg","width":1792,"height":1024,"caption":"toposuranos.com"},{"@type":"BreadcrumbList","@id":"http:\/\/toposuranos.com\/material\/en\/functions-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"http:\/\/toposuranos.com\/material\/es\/cursos-de-matematica-y-fisica\/"},{"@type":"ListItem","position":2,"name":"Functions in C++"}]},{"@type":"WebSite","@id":"http:\/\/toposuranos.com\/material\/#website","url":"http:\/\/toposuranos.com\/material\/","name":"toposuranos.com\/material","description":"","publisher":{"@id":"http:\/\/toposuranos.com\/material\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/toposuranos.com\/material\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"http:\/\/toposuranos.com\/material\/#organization","name":"toposuranos.com\/material","url":"http:\/\/toposuranos.com\/material\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"http:\/\/toposuranos.com\/material\/#\/schema\/logo\/image\/","url":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2023\/10\/logo.png","contentUrl":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2023\/10\/logo.png","width":2400,"height":2059,"caption":"toposuranos.com\/material"},"image":{"@id":"http:\/\/toposuranos.com\/material\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/groups\/toposuranos","https:\/\/x.com\/topuranos","https:\/\/www.youtube.com\/channel\/UC16yDm12cPcrwsE0fAM7X1g","https:\/\/www.linkedin.com\/company\/69429190"]},{"@type":"Person","@id":"http:\/\/toposuranos.com\/material\/#\/schema\/person\/e15164361c3f9a2a02cf6c234cf7fdc1","name":"giorgio.reveco","image":{"@type":"ImageObject","inLanguage":"es","@id":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2023\/10\/1694478625378-96x96.jpeg","url":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2023\/10\/1694478625378-96x96.jpeg","contentUrl":"http:\/\/toposuranos.com\/material\/wp-content\/uploads\/2023\/10\/1694478625378-96x96.jpeg","caption":"giorgio.reveco"},"description":"Soy Licenciado en F\u00edsica, Magister en Ingenier\u00eda Industrial y Docente Universitario. Me dedico a desmitificar la f\u00edsica y las matem\u00e1ticas. Mi objetivo es hacer que estos campos sean f\u00e1cilmente comprensibles para todos, proporcionando las herramientas para explorar no solo el mundo que nos rodea, sino tambi\u00e9n las profundidades de nuestra propia existencia y el orden natural que nos conecta con el cosmos.","sameAs":["http:\/\/toposuranos.com\/material"],"url":"http:\/\/toposuranos.com\/material\/author\/giorgio-reveco\/"}]}},"_links":{"self":[{"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/posts\/31433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/comments?post=31433"}],"version-history":[{"count":0,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/posts\/31433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/media\/31365"}],"wp:attachment":[{"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/media?parent=31433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/categories?post=31433"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/toposuranos.com\/material\/wp-json\/wp\/v2\/tags?post=31433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}