Overview
Creation and maintenance of the program becomes difficult when the lines of code in the program increase. As the size of the program increases, the code becomes more prone to errors and the debugging of the program becomes difficult. The line of code (LOC) is considered as one of the metrics to determine the logical complexity of the program in the software development life cycle. Any program is a sequence of instructions and there can be a situation where a subsequence needs to be repeatedly executed at different places in the program. Repeating the subsequence at each place will not only increase the LOC but also make the program bulky and hamper its readability, thereby making change management cumbersome. Imagine a situation wherein a certain operation (say performing addition) is repeatedly written in the program at 100 different places, and suddenly you realize that you need to perform subtractions instead of additions. Making this change is going to be difficult because you need to ensure that all the addition operations at 100 different places need to change to subtraction. And what if you miss one of them to change? Or what if you change something else by mistake in a rush to make these 100 changes? The problem is that there is a lot of duplication of code (redundancy of code), and hence making one change requires making multiple changes.
In C/C++, it is possible to split a large program into multiple independent pieces. Each independent piece is called a function or a method. A function can define a single operation or a sequence of operations. You can invoke a function whenever you need to execute the operations it defines. Hence, the idea is to define an operation only once within the function and invoke the same function at multiple places where you need to perform the operation. A function can have multiple inputs (called arguments) and generate a single output (called return value) as shown in Figure 7.1.
Review the options below to login to check your access.
Log in with your Cambridge Aspire website account to check access.
If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.