100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

COS132 Chapter 6 Summary

Rating
-
Sold
-
Pages
7
Uploaded on
20-04-2022
Written in
2021/2022

Very detailed summaries.

Institution
Module









Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Module

Document information

Summarized whole book?
Yes
Uploaded on
April 20, 2022
Number of pages
7
Written in
2021/2022
Type
Summary

Subjects

Content preview

COS132 Chapter 6



COS 132
CHAPTER 6 – FUNCTIONS

UNIT 6.1- FOCUS ON SOFTWARE ENGINEERING: MODULAR PROGRAMMING

A program may be broken up into manageable functions.

A function = collection of statements that perform a specific task.

- We have experienced functions in two ways:
o Creating “main” in every program
o Library functions
 Pow
 Strcmp

Using functions can be called divide and conquer as a large problem is divided.

Benefit of using functions is code reuse.

UNIT 6.2 – DEFINING AND CALLING FUNCTIONS

Function call = statement that causes a function to execute, a function definition contains the statements that make up the function.

When creating a function, you must write its definition, all function definitions have the following parts:




VOID FUNCTIONS
Some functions simply perform one or more statements, and then terminate – they are known as void functions. This means the
function does not return a value to the part of the program that executed it. Also notice the function has no return statement


CALLING A FUNCTION
Function main is automatically called when a program starts, but all other functions must be executed by function call statements.

Function header ---- void functionName()

, COS132 Chapter 6

Function call --- functionName();

UNIT 6.3 – FUNCTION PROTOTYPES / FUNCTION DECLARATIONS

A function prototype eliminates the need to place a function definition before all calls to the function.

Before the complier encounters a call to a particular function, it must already know the function’s return type, the number of
parameters it uses, and the type of each parameter. One way of ensuring that the compiler has this info is to place the function
definition before all calls to that function.

Another method is to declare the function w a function prototype, (void functionName(); ) the prototype looks similar to the
function header, except there is a semicolon at the end.

Function prototypes are usually placed near the top of a program so the compiler will encounter them before any function calls.

UNIT 6.4 – SENDING DATA INTO A FUNCTION

When a function is called, the program may send values into the function. These values are called arguments.

The values that are passed into a function are called arguments, and the variables that receive those values are called parameters.
There are several variations of these terms in use. Some call the arguments actual parameters and call the parameters formal
parameters. Others use the terms actual argument and formal argument. Regardless of which set of terms you use, it is important to
be consistent




If you pass an argument whose type is not the same as the parameter’s type, the argument will be promoted or demoted
automatically.

Parameters have a scope – limited to the body of the function that uses it.

UNIT 6.5 – PASSING DATA BY VALUE

When an argument is passed into a parameter, only a copy of the arguments value is passed. Changes to the parameter do not affect
the OG argument.

Parameters are special-purpose variables that are defined inside the parentheses of a function definition. They are separate and
distinct from the arguments that are listed inside the parentheses of a function call. The values that are stored in the parameter
variables are copies of the arguments. Normally, when a parameter’s value is changed inside a function, it has no effect on the
original argument.

UNIT 6.6 – FOCUS ON SOFTWARE ENGINEERING: USING FUNCTIONS IN A MENU-DRIVEN PROGRAM

Functions are ideal for use in menu-driven programs, when the user selects an item from a menu, the program can call the
appropriate function.
£4.05
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
jennamortonx IIE Varsity College
Follow You need to be logged in order to follow users or courses
Sold
18
Member since
3 year
Number of followers
1
Documents
49
Last sold
5 months ago

4.0

1 reviews

5
0
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions