Professional Documents
Culture Documents
Programming Fundamentals
Introduction to
Functions
Instructor:
Dr. Ayesha Hakim
Department of Computer Science
To familiarize
Learning students with the
Objective development of
modular programs
using functions.
Introduction
myFunction();
Example
void myFunction()
{
cout << "I just got executed!";
}
int main() {
myFunction();
myFunction();
myFunction();
return 0;
}
Output?
Information can be passed to
functions as a parameter.
Parameters act as variables inside
the function.
Arguments
void functionName(parameter1, par
ameter2, parameter3) {
// code to be executed
}
Return Values
• int myFunction(int x) {
return 5 + x;
}
int main() {
cout << myFunction(3);
return 0;
}
// Output: 8 (5 + 3)
Lab Exercise
Types of Functions
• User-defined functions
• Built-in functions