You are on page 1of 31

Structured Programming

Eng. Asmaa AbdulQawy


“Functions”
C++ Functions

Predefined in C++ Created by users


C++ Predefined Functions

• Library functions are the built-in functions in C++ programming.


• library functions is used by invoking the functions directly; they don't
need to write the functions themselves.
• In order to use library functions, we usually need to include the header
file in which these library functions are defined.
• For instance, in order to use mathematical functions such
as sqrt() and abs(), we need to include the header file cmath.

C++ Predefined Functions
Program to get square root of number
C++ Predefined Functions
Program to get size of string
C++ User-defined Functions
return_type Function_Name(param1,param2,….param3 )
{
//function’s body
}
Function Parameters
Function Parameters- One Parameter
Function Parameters – Multi Parameters
Return Statement
Function Prototype
In C++, the code of function declaration
should be before the function call. However, if
we want to define a function after the function
call, we need to use the function prototype.
Function Prototype
Function with Parameters and No return
Function with Parameters and Return
Get Prime number with No arguments
passed and no return value
Get Prime number with No arguments
passed but a return value
Get Prime number with Arguments
passed and a return value
Get Prime number with Arguments
passed but no return value
Get factorial of number using function
Find Cube of a Number using function
Swap two numbers using function
Swap two numbers using function
Swap two numbers using call by value I
Swap two numbers using call by value II
Call by value and call by reference in C++
Reference to a variable
Swap two numbers using call by reference
Swap two numbers using call by reference
Swap two numbers using call by value &
Reference
Passing Parameters by Reference
Assignment using Functions

You might also like