Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

C++ FUNCTIONS

WHAT ARE C++ FUNCTIONS?


 A function is a block of code that performs some
operation.

 A function can optionally define input parameters that


enable callers to pass arguments into the function.

 A function can optionally return a value as output.

 You can call function several times in your program.


WHAT ARE THE ADVANTAGES OF
USING C++ FUNCTIONS IN THE
PROGRAM?
 Easier to Code.
 Easier to Modify.
 Easier to Maintain & Debug.
 Reusability.
 Less Programming Time.
WHAT ARE TWO TYPES OF
C++ FUNCTIONS?
1.Pre-defined, or library functions
These functions are part of the compiler package. These are
part of the standard library made available by the compiler. For
example, exit(), sqrt(), pow(), strlen(), etc. are library functions
(built-in functions).
WHAT ARE TWO TYPES OF
C++ FUNCTIONS?
Built-in functions are also called library functions. These are the functions that are
provided by C++ and we need not write them ourselves. We can directly use these
functions in our code.
These functions are placed in the header files of C++. For Example, <cmath>,
<cstring> are the headers that have in-built math functions and string functions
respectively.
2. C++ user-defined functions
The user-defined functions are created by you,
i.e., the programmer. These functions are created
as per the requirements of your program.
A parameter is a variable in a
function definition. It is a
placeholder and hence does not
have a concrete value.
The argument is a value passed
during function invocation.
Types of User Defined Functions Based on
Parameter and Return Value:
1. Function with no arguments and no return value
2. Function with no arguments and a return value
3. Function with arguments and no return value
4. Function with arguments and with return value

You might also like