0% found this document useful (0 votes)
6 views

Functions in Programming Information Communication Technology

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Functions in Programming Information Communication Technology

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COMSATS SAHIWAL

FUNCTIONS IN
PROGRAMMIN
G
Abdullah Saleh Waqas Khushi Zain
WHAT IS A
FUNCTION?

• Definition: A function is a block


of organized, reusable code that
performs a single action.

• Purpose: Helps break down


complex problems, promotes
code reusability, and enhances
readability.
1. PREDEFINED FUNCTIONS
Predefined functions are functions that are already
built into a programming language. They’re ready
to use, which means you don’t have to write any
additional code to define them; you can just call
them whenever you need them.

Examples:
• print(): Used to output text or variables to the
console. Example: print("Hello, World!")
2. USER-DEFINED
FUNCTIONS
User-defined functions are functions that
programmers create to perform specific tasks not
covered by predefined functions. They’re especially
useful for organizing code, breaking down complex
problems, and reusing code across different parts
of a program.
Examples:
• Imagine you frequently need to calculate the
area of a rectangle. Instead of repeatedly
writing the formula, you could create a user-
defined function
COMPARISON
Definition Definition

Predefined functions are built-in functions in a programming User-defined functions are custom functions created by
language that you can use directly without writing any extra programmers to perform specific tasks, making code more
code. Simply call the function to perform its task, like print() to organized, reusable, and suited to unique needs.
display text or len() to find the length of a string.

Examples Examples

print(), len(), sqrt() greet(), area_of_rectangle() (user-defined)

Flexibility Flexibility

Limited to existing functions Customizable to fit specific tasks

Ease of Use Ease of Use

Ready to use; just call the function Requires defining the function before use
USING
PREDEFINED
FUNCTIONS
How to Use Them:
• Simply call the function by its name, followed by parentheses containing any
required arguments.

Examples:
• print("Hello, World!") – Displays the text "Hello, World!" on the screen.

public class Main {


public static void main (String[] args) {
// Using the predefined function System.out.println to print text
System.out.println("Hello, World!");

}
}
DEFINING FUNCTIONS CALLING FUNCTIONS

• def function_name (parameters): • function_name (arguments)


• Parameters are optional inputs to the function. • Arguments are the actual values passed to the
function.

EXAMPLE:

def greet (name):

print ("Hello, " + name +


"!")

greet("Alice")
KEY COMPETITIVE
ADVANTAGES

Parameter Passing Function Return Values


• Parameters: Values passed to a • Void Functions:Perform actions but
function to customize its behavior. don't return a value.
• Types of Parameters:Positional • Often used for side effects like printing
Arguments: Order matters. to the console or modifying variables.

Value-Returning Functions:
• Return a value that can be used in
other parts of the program.
• Often used for calculations or data
processing.
COMSATS SAHIWAL

THANK
YOU
for your time and attention

Abdullah Saleh Waqas Khushi Zain

You might also like