SlideShare a Scribd company logo
Presented by : 
Arinda Lailatul Karimah 4101412109 
Septi Ratnasari 4101412082
Description 
 A function is a group of statements that together 
perform a task. 
 Every Pascal program has at least one function which is 
the program itself, and all the most trivial programs can 
define additional functions. 
 A function declaration tells the compiler about a 
function's name, return type, and parameters. A 
function definition provides the actual body of the 
function.
 A function is similar to a procedure. 
 Procedures accept data or variables when they are 
executed. Functions also accept data, but have the ability 
to return a value to the procedure or program which 
requests it. 
 Functions are used to perform mathematical tasks like 
factorial calculations. 
 A function : 
1. begins with the keyword function 
2. is similar in structure to a procedure 
3. somewhere inside the code associated with the 
function, a value is assigned to the function name 
4. a function is used on the righth and side of an 
expression 
5. can only return a simple data type
 The only difference from the procedure is that the 
function return a value at the end. Note that a procedure 
cannot return a value. A function start and end in a 
similar way to that of a procedure. 
 If more than one value is required to be returned by a 
module, we should make use of the variable parameter. A 
function can have parameters too. If we change the sub-program 
from procedure to a function, of the previous 
program, there will be no difference in the output of the 
program. 
 Just make sure which one is best when we can to 
implement a module. For example, if we don't need to 
return any values, a procedure is more best. However if a 
value should be returned after the module is executed, 
function should be used instead.
 In Pascal, a function is defined using the function 
keyword. The general form of a function definition is 
as follows: 
function name(argument(s): type1; argument(s): type2; ...): 
function_type; 
local declarations; 
begin 
... 
< statements > 
... 
name:= expression; 
end;
 A function definition in Pascal consists of a function 
header, local declarations and a function body. The 
function header consists of the keyword function and a 
name given to the function.
Here are all the parts of a function: 
1. Arguments: 
The argument(s) establish the linkage between the calling 
program and the function identifiers and also called the 
formal parameters. 
 A parameter is like a placeholder. When a function is 
invoked, we 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. Use of such formal 
parameters is optional. These parameters may have 
standard data type, user-defined data type or subrange 
data type. 
 The formal parameters list appearing in the function 
statement could be simple or subscripted variables, 
arrays or structured variables, or subprograms.
2. Return Type: 
All functions must return a value, so all functions must 
be assigned a type. 
The function-type is the data type of the value the 
function returns. It may be standard, user-defined scalar 
or subrange type but it cannot be structured type.
3. Local declarations: 
local declarations refer to the declarations for labels, 
constants, variables, functions and procedures, which are 
application to the body of function only.
4. Function Body: 
The function body contains a collection of 
statements that define what the function does. 
It should always be enclosed between the 
reserved words begin and end. It is the part of a 
function where all computations are done. 
There must be an assignment statement of the 
type - name := expression; in the function body 
that assigns a value to the function name. This 
value is returned as and when the function is 
executed. The last statement in the body must 
be an end statement.
 Following is an example showing how to define a function in pascal: 
(* function returning the max between two numbers *) 
function max(num1, num2: integer): integer; 
var 
(* local variable declaration *) 
result: integer; 
begin 
if (num1 > num2) then 
result := num1 
else 
result := num2; 
max := result; 
end;
Function Declarations 
 A function declaration tells the compiler about a function 
name and how to call the function. The actual body of the 
function can be defined separately. 
 A function declaration has the following parts: 
function name(argument(s): type1; argument(s): type2; ...): 
function_type; 
 For the above defined function max(), following is the 
function declaration: 
function max(num1, num2: integer): integer;
 Function declaration is required when we define a 
function in one source file and we call that function in 
another file. In such case we should declare the function 
at the top of the file calling the function.
Calling a Function 
 While creating a function, we give a definition of what 
the function has to do. 
 To use a function, we will have to call that function to 
perform the defined task. When a program calls a 
function, program control is transferred to the called 
function. 
 A called function performs defined task and when its 
return statement is executed or when it last end 
statement is reached, it returns program control back to 
the main program.
To call a function we simply need to pass the required parameters 
along with function name and if function returns a value then we 
can store returned value. Following is a simple example to show 
the usage:
Assigning a value to a function identifier 
 The function's block definition must include a statement 
that assigns a value to the function's identifier. This is 
how a function gets a value that it can return to the 
caller. 
 If we omit this assignment statement, or the assignment 
statement does not get executed as a result of 
conditional statements in the function's code, then the 
function returns an undefined or potentially random 
value. If during the course of debugging a program we 
find our functions returning erratic values, be certain 
that the function identifier is correctly assigned a value.
Acceptable Function Return Values 
 The data type that a function returns can be any of the 
following: 
a. Any ordinal value, including Boolean, Byte, Char, Smallint, 
Integer, Word, Longint, and enumarated data types and 
user defined sub range types. 
b. Real, Single, Double, Extended and Comp data types, 
c. Pointer values 
d. Strings. 
 Functions may not return records or sets, although they may 
return pointers to records or sets.
Recursive Function 
 Functions may call themselves. Such a function is called a 
recursive function. A popular and simple example of a 
recursive function is a function that computes the factorial 
of a number. The factorial of a number n, is n * (n-1) * (n-2) 
... until n reaches 1.
Important note: 
The effect of short-circuit evaluation on functions 
 By default, Turbo Pascal generates short-circuit evaluation code, so it is 
possible that a function may not be called within a particular expression. 
For example, consider a function defined as: 
function ValueInRange ( X1 : Integer ) : Boolean; 
begin 
... 
if X1 > 0 then 
ValueInRange := True 
else 
ValueInRange := False; 
if X1 < LowestCoordinate then 
LowestCoordinate := X1; 
end;
 In this function, a global variable LowestCoordinate may 
have its value changed during the course of execution. If 
this function is called in an expression such as, 
if (X1<>X2) and ValueInRange(X1) then ...
Function as Parameter 
 A function may itself be passed to another function as a 
parameter value. To pass a requires that a type 
declaration define a procedure type that matches the 
appropriate function header. This type becomes the 
parameter type used in the procedure parameter list.
Fungsi Add
Fungsi Max-ab
Fungsi Genap - Ganjil
Fungsi Midpoint
Fungsi Phytagoras
Fungsi Luas 
Segitiga
Fungsi Luas 
Persegi Panjang
Fungsi Volume 
Balok
Functions

More Related Content

What's hot

Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Function
FunctionFunction
Function
Saniati
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
Meghaj Mallick
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
Java script function
Java script functionJava script function
Java script function
suresh raj sharma
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6patcha535
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
C functions
C functionsC functions
Functions
FunctionsFunctions
Functions
PatriciaPabalan
 
Function
FunctionFunction
Function
rishabh agrawal
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
Saket Pathak
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 

What's hot (20)

Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function
FunctionFunction
Function
 
user defined function
user defined functionuser defined function
user defined function
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Java script function
Java script functionJava script function
Java script function
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
C functions
C functionsC functions
C functions
 
Functions
FunctionsFunctions
Functions
 
Function
FunctionFunction
Function
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Functions in python
Functions in python Functions in python
Functions in python
 
Unit 8
Unit 8Unit 8
Unit 8
 

Viewers also liked

Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1
Ayu Karisma Alfiana
 
Pemrograman komputer 9 (database)
Pemrograman komputer  9 (database)Pemrograman komputer  9 (database)
Pemrograman komputer 9 (database)
jayamartha
 
Program pascal menghitung ipk
Program pascal menghitung ipkProgram pascal menghitung ipk
Program pascal menghitung ipk
Arjanggi Nv
 
4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.netRief Fiandi
 
Pengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIPengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIWahyu Primadi
 
Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2
Ayu Karisma Alfiana
 
123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004Nurdin Al-Azies
 
03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net 03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net
Ayu Karisma Alfiana
 
Algoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer IAlgoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer I
Chandra Septianoor
 
Materi Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis DesktopMateri Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis Desktop
Naufal Arifudzaki
 
27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii
Ayu Karisma Alfiana
 
05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii
Ayu Karisma Alfiana
 
Part 10 pengantar basis data
Part 10 pengantar basis dataPart 10 pengantar basis data
Part 10 pengantar basis data
Dermawan12
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Teknik Informatika UII
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CNurdin Al-Azies
 
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Nurdin Al-Azies
 
Basis data
Basis dataBasis data
Basis data
dicky pratama
 
Membuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaMembuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaEko Kurniawan Khannedy
 
Aplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstopAplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstop
alfian_nasir
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
Fernando Torres
 

Viewers also liked (20)

Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1
 
Pemrograman komputer 9 (database)
Pemrograman komputer  9 (database)Pemrograman komputer  9 (database)
Pemrograman komputer 9 (database)
 
Program pascal menghitung ipk
Program pascal menghitung ipkProgram pascal menghitung ipk
Program pascal menghitung ipk
 
4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net
 
Pengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIPengantar Pemrograman Visual II
Pengantar Pemrograman Visual II
 
Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2
 
123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004
 
03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net 03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net
 
Algoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer IAlgoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer I
 
Materi Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis DesktopMateri Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis Desktop
 
27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii
 
05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii
 
Part 10 pengantar basis data
Part 10 pengantar basis dataPart 10 pengantar basis data
Part 10 pengantar basis data
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam Pascal
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman C
 
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
 
Basis data
Basis dataBasis data
Basis data
 
Membuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaMembuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan java
 
Aplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstopAplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstop
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 

Similar to Functions

User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
NabeelaNousheen
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Functions
FunctionsFunctions
Functions
zeeshan841
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
TeshaleSiyum
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
C functions list
C functions listC functions list
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
KavithaChekuri3
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
nikshaikh786
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 

Similar to Functions (20)

User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Functions
FunctionsFunctions
Functions
 
Functions
Functions Functions
Functions
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
C functions list
C functions listC functions list
C functions list
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
Function in c
Function in cFunction in c
Function in c
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Functions
FunctionsFunctions
Functions
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 

More from Septi Ratnasari

Pengujian Hipotesis
Pengujian HipotesisPengujian Hipotesis
Pengujian Hipotesis
Septi Ratnasari
 
Sanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkunganSanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkungan
Septi Ratnasari
 
Hakikat Pendidikan
Hakikat PendidikanHakikat Pendidikan
Hakikat Pendidikan
Septi Ratnasari
 
Curved Sides
Curved SidesCurved Sides
Curved Sides
Septi Ratnasari
 
Kedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanKedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanSepti Ratnasari
 
Graf Pohon
Graf PohonGraf Pohon
Graf Pohon
Septi Ratnasari
 
English Conversation in the School
English Conversation in the SchoolEnglish Conversation in the School
English Conversation in the SchoolSepti Ratnasari
 
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Septi Ratnasari
 

More from Septi Ratnasari (11)

Pengujian Hipotesis
Pengujian HipotesisPengujian Hipotesis
Pengujian Hipotesis
 
Sanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkunganSanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkungan
 
Hakikat Pendidikan
Hakikat PendidikanHakikat Pendidikan
Hakikat Pendidikan
 
Curved Sides
Curved SidesCurved Sides
Curved Sides
 
Kedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanKedudukan BK dalam Pendidikan
Kedudukan BK dalam Pendidikan
 
Graf Pohon
Graf PohonGraf Pohon
Graf Pohon
 
Circle Terminology
Circle TerminologyCircle Terminology
Circle Terminology
 
English Conversation in the School
English Conversation in the SchoolEnglish Conversation in the School
English Conversation in the School
 
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
 
Permasalahan Sampah
Permasalahan SampahPermasalahan Sampah
Permasalahan Sampah
 
Mathematical Logic
Mathematical LogicMathematical Logic
Mathematical Logic
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

Functions

  • 1. Presented by : Arinda Lailatul Karimah 4101412109 Septi Ratnasari 4101412082
  • 2. Description  A function is a group of statements that together perform a task.  Every Pascal program has at least one function which is the program itself, and all the most trivial programs can define additional functions.  A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
  • 3.  A function is similar to a procedure.  Procedures accept data or variables when they are executed. Functions also accept data, but have the ability to return a value to the procedure or program which requests it.  Functions are used to perform mathematical tasks like factorial calculations.  A function : 1. begins with the keyword function 2. is similar in structure to a procedure 3. somewhere inside the code associated with the function, a value is assigned to the function name 4. a function is used on the righth and side of an expression 5. can only return a simple data type
  • 4.  The only difference from the procedure is that the function return a value at the end. Note that a procedure cannot return a value. A function start and end in a similar way to that of a procedure.  If more than one value is required to be returned by a module, we should make use of the variable parameter. A function can have parameters too. If we change the sub-program from procedure to a function, of the previous program, there will be no difference in the output of the program.  Just make sure which one is best when we can to implement a module. For example, if we don't need to return any values, a procedure is more best. However if a value should be returned after the module is executed, function should be used instead.
  • 5.  In Pascal, a function is defined using the function keyword. The general form of a function definition is as follows: function name(argument(s): type1; argument(s): type2; ...): function_type; local declarations; begin ... < statements > ... name:= expression; end;
  • 6.  A function definition in Pascal consists of a function header, local declarations and a function body. The function header consists of the keyword function and a name given to the function.
  • 7. Here are all the parts of a function: 1. Arguments: The argument(s) establish the linkage between the calling program and the function identifiers and also called the formal parameters.  A parameter is like a placeholder. When a function is invoked, we 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. Use of such formal parameters is optional. These parameters may have standard data type, user-defined data type or subrange data type.  The formal parameters list appearing in the function statement could be simple or subscripted variables, arrays or structured variables, or subprograms.
  • 8. 2. Return Type: All functions must return a value, so all functions must be assigned a type. The function-type is the data type of the value the function returns. It may be standard, user-defined scalar or subrange type but it cannot be structured type.
  • 9. 3. Local declarations: local declarations refer to the declarations for labels, constants, variables, functions and procedures, which are application to the body of function only.
  • 10. 4. Function Body: The function body contains a collection of statements that define what the function does. It should always be enclosed between the reserved words begin and end. It is the part of a function where all computations are done. There must be an assignment statement of the type - name := expression; in the function body that assigns a value to the function name. This value is returned as and when the function is executed. The last statement in the body must be an end statement.
  • 11.  Following is an example showing how to define a function in pascal: (* function returning the max between two numbers *) function max(num1, num2: integer): integer; var (* local variable declaration *) result: integer; begin if (num1 > num2) then result := num1 else result := num2; max := result; end;
  • 12.
  • 13. Function Declarations  A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately.  A function declaration has the following parts: function name(argument(s): type1; argument(s): type2; ...): function_type;  For the above defined function max(), following is the function declaration: function max(num1, num2: integer): integer;
  • 14.  Function declaration is required when we define a function in one source file and we call that function in another file. In such case we should declare the function at the top of the file calling the function.
  • 15. Calling a Function  While creating a function, we give a definition of what the function has to do.  To use a function, we will have to call that function to perform the defined task. When a program calls a function, program control is transferred to the called function.  A called function performs defined task and when its return statement is executed or when it last end statement is reached, it returns program control back to the main program.
  • 16. To call a function we simply need to pass the required parameters along with function name and if function returns a value then we can store returned value. Following is a simple example to show the usage:
  • 17.
  • 18. Assigning a value to a function identifier  The function's block definition must include a statement that assigns a value to the function's identifier. This is how a function gets a value that it can return to the caller.  If we omit this assignment statement, or the assignment statement does not get executed as a result of conditional statements in the function's code, then the function returns an undefined or potentially random value. If during the course of debugging a program we find our functions returning erratic values, be certain that the function identifier is correctly assigned a value.
  • 19. Acceptable Function Return Values  The data type that a function returns can be any of the following: a. Any ordinal value, including Boolean, Byte, Char, Smallint, Integer, Word, Longint, and enumarated data types and user defined sub range types. b. Real, Single, Double, Extended and Comp data types, c. Pointer values d. Strings.  Functions may not return records or sets, although they may return pointers to records or sets.
  • 20. Recursive Function  Functions may call themselves. Such a function is called a recursive function. A popular and simple example of a recursive function is a function that computes the factorial of a number. The factorial of a number n, is n * (n-1) * (n-2) ... until n reaches 1.
  • 21.
  • 22. Important note: The effect of short-circuit evaluation on functions  By default, Turbo Pascal generates short-circuit evaluation code, so it is possible that a function may not be called within a particular expression. For example, consider a function defined as: function ValueInRange ( X1 : Integer ) : Boolean; begin ... if X1 > 0 then ValueInRange := True else ValueInRange := False; if X1 < LowestCoordinate then LowestCoordinate := X1; end;
  • 23.  In this function, a global variable LowestCoordinate may have its value changed during the course of execution. If this function is called in an expression such as, if (X1<>X2) and ValueInRange(X1) then ...
  • 24. Function as Parameter  A function may itself be passed to another function as a parameter value. To pass a requires that a type declaration define a procedure type that matches the appropriate function header. This type becomes the parameter type used in the procedure parameter list.
  • 25.
  • 28. Fungsi Genap - Ganjil