100% found this document useful (1 vote)
102 views21 pages

C++ Functions: Presented by Kathryne Tarrayo and Jester Tiu

This document discusses functions in C++. It defines a function as a segment of code that performs a specific task. There are two types of functions: library/built-in functions and user-defined functions. User-defined functions allow programmers to define their own code segments. A user-defined function consists of a name, body, return value, parameters, and arguments. Library functions are pre-written functions in C++ libraries that can be directly called without defining.

Uploaded by

Rin Sohn
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
100% found this document useful (1 vote)
102 views21 pages

C++ Functions: Presented by Kathryne Tarrayo and Jester Tiu

This document discusses functions in C++. It defines a function as a segment of code that performs a specific task. There are two types of functions: library/built-in functions and user-defined functions. User-defined functions allow programmers to define their own code segments. A user-defined function consists of a name, body, return value, parameters, and arguments. Library functions are pre-written functions in C++ libraries that can be directly called without defining.

Uploaded by

Rin Sohn
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 21

C++ Functions

◇ Presented by Kathryne Tarrayo and Jester Tiu


What is a Function?
Function
In programming, function refers to a segment
that groups code to perform a specific task.

Depending on whether a function is


predefined or created by programmer; there
are two types of function:

1. Library Function / Built-in Function


2. User-defined Function
User-Defined Function
C++ allows programmer to define their own function.

A user defined function groups code to perform a


specific task and that group of code is given a
name(identifier).

When the function is invoked from any part of program,


it all executes the codes defined in the body of function.

int main() function1();

{
statement;
function1();
return;
function2(); function3();
statement
function2(); statement
statement; function3();

function4(); return; return;


statement;
function4();

return 0;

} return;
User-defined Function
It consist of the following:

Function Names,
Function Body,
Return Values,
Parameters,
Arguments
return_type function_name ( parameter list )

Function Name − This is the actual


name of the function. The function


name and the parameter list together
constitute the function signature.

Parameters − A parameter is like a


placeholder. When a function is
invoked, you pass a value to the
parameter. This value is referred to as
actual parameter or argument. The
parameter list refers to the type, order,
and number of the parameters of a
function. Parameters are optional; that
is, a function may contain no
parameters.
“ Function Body − The
function body contains a
collection of statements that
define what the function
does.
function_name variable_name

Calling function − To use a function, you


will have to call or invoke that function.
When a program calls a function,
program control is transferred to the
called function.
variable_name

Return Statement − A


function may return a value.
Some functions perform the
desired operations without
returning a value.


Library function
Library function
• Library functions are the built-in function in C++
programming.
• Programmer can use library function by invoking
function directly; they don't need to write it
themselves.
• Completely debugged, efficient and always
produce a precise output.
• We need not to declare and define these functions
as they are already written in the C++ libraries
such as iostream, cmath etc.
• Can directly call when needed.

Examples of built-in functions
TITLE DESCRIPTION

pow() Computes Power a Number

remainder() Returns remainder of x/y

sqrt() Computes Square Root of A Number

cbrt() Computes Cube Root of a Number


pow()
remainder()
sqrt()
cbrt()

You might also like