Professional Documents
Culture Documents
Functions
Types of Functions:
1.Void Functions
There are functions which do not return a value but only
prints messages on the screen. These are called void
functions.
2. Overloading Functions
Function overloading is a feature of object-oriented
programming (OOP) where two or more functions can have the
same name but different parameters.
Unit 3. Functions
1.Void Functions
Void functions are created and used just like value-
returning functions except they do not return a value after
the function executes. In lieu of a data type, void functions
use the keyword "void.“
A void function performs a task, and then control
returns back to the caller--but, it does not return a value.
You may or may not use the return statement, as there is no
return value.
Unit 3. Functions
Example of Void Function:
Fuction
void message() { Definition
cout<<“Kim Sunoo”;
cout<<endl;
cout<<“18 years old”;
}
int main () {
Fuction Call
message();
return EXIT_SUCCESS;
}
Unit 3. Functions void message() {
cout<<“Kim Sunoo”;
cout<<endl;
cout<<“18 years old”;
Example of Overloading Function: }
return EXIT_SUCCESS;
}
Kim Sunoo _
_18 years old
Computer Monitor
Unit 3. Functions
Create a void Structure That Will Print Your Teacher’s Name,age And What Age
Does She Looks Like
void print(string c) {
void print(char f) {
void print(int i) {
cout << "Looks like: " << i << endl;
}
Int main() {
print("Vee Arbee");
print(52);
print(18);
return EXIT_SUCCESS;
}
void print(string c) {
Unit 3. Functions
cout << "Teacher's name: " << c;
cout <<endl;
}
void print(char f) {
SIMULATION: }
cout << "Looks like: " << i << endl;
cout <<endl;
int main() {
print("Vee Arbee");
Teacher’s name: Vee Arbee _ print(52);
print(18);
_
Age: 52 _
Looks
_ like: 18 _
_
52
Vee Arbee
f 18
Computer Monitor
c i
Unit 3. Functions
2. Overloading Functions
An overloaded declaration is a declaration that is declared with
the same name as a previously declared declaration in the same
scope, except that both declarations have different arguments and
obviously different definition (implementation).
When you call an overloaded function or operator, the compiler
determines the most appropriate definition to use, by comparing
the argument types you have used to call the function or operator
with the parameter types specified in the definitions. The process of
selecting the most appropriate overloaded function or operator is
called overload resolution.
Unit 3. Functions Fuction
Example of Overloading Function:
void display(int var1, double var2) Definition
{
cout << "Integer number = " << var1;
cout << " and double number = " << var2;
cout<<endl;
}
Unit 3. Functions
cout << "Integer number = " << var1;
cout << " and double number = " << var2;
cout<<endl;
}
_
Float number = 5.5 _ 5 5.5
double b = 5.5;
display(a);
Integer
_ number = 5 and double number = 5.5 _ display(b);
var var
display(a, b);
_
5 5.5
Computer Monitor
var 1 var 2
Group 1 We hope you
learn something
Thank you
everyone