0% found this document useful (0 votes)
5 views5 pages

Functions

The document explains the distinction between predefined (built-in) functions and user-defined functions in programming. It outlines the components of a function, including return type, function name, argument list, and function body, as well as the process of creating and calling functions. Additionally, it categorizes user-defined functions based on the presence of arguments and return values.

Uploaded by

abdullahirfanhps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Functions

The document explains the distinction between predefined (built-in) functions and user-defined functions in programming. It outlines the components of a function, including return type, function name, argument list, and function body, as well as the process of creating and calling functions. Additionally, it categorizes user-defined functions based on the presence of arguments and return values.

Uploaded by

abdullahirfanhps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Functions

System define/Predefine functions


A predefine function is also referred to as a built-in function or library function or system
function. A compiler package already exists that contains these functions, each of which has a
specific meaning and is included in the package. Built-in functions have the advantage of being
directly usable without being defined, whereas user-defined functions must be declared and
defined before being used.
Example: main(), pow(), abs (), sqrt(), clrscr()

User define functions


Functions that the programmer creates are known as User-Defined functions or “tailor-made
functions”. User-defined functions can be improved and modified according to the need of the
programmer. Whenever we write a function that is case-specific and is not defined in any header
file, we need to declare and define our own functions according to the syntax.
Parts of Function:
 Return Type − A function may return a value. The return_type is the data type of the
value the function returns. Some functions perform the desired operations without
returning a value. In this case, the return_type is the keyword void.
 Function Name − This is the actual name of the function. The function name and the
parameter list together constitute the function signature.
 Argument List − An argument (also called parameter) is like a placeholder. When a
function is called, you pass a value as a parameter. This value is referred to as the actual
parameter or argument. The parameter list refers to the type, order, and number of the
parameters of a function. Parameters are optional; that is, a function may contain no
parameters.
 Function Body − The function body contains a collection of statements that defines what
the function does.
Creating a Function:
 Function Declaration/Prototype: In C language function prototype is used to provide
function declaration. It defines the function's name, returns types, and parameters. The
return types are the data types that the function returns after execution. If a function
returns an integer, the return type is int. When a function returns a float value, the return
type is also a float. Similarly, a void function does not return any value. The name of the
function is used to uniquely identify it.
 Function Definition: The actual implementation of the function is included in the
function definition. It specifies what the function is expected to perform. The main logic
of the function is written here. The control is handed to the function definition when the
program calls the function and the control returns to the main function when the function
is executed and completed.

 Function Call: A function call is a statement that instructs the compiler to execute the
function. We use the function name and parameters in the function call.
Four methods of user define functions
There are four types of user-defined functions divided on the basis of arguments they accept and
the value they return:
1. Function with No Arguments and No Return Value
Functions that have no arguments and no return values. Such functions can either be used to
display information or to perform any task on global variables.

2. Function with No Arguments and With Return Value


Functions that have no arguments but have some return values.
3. Function With Arguments and No Return Value
Functions that have arguments but no return values.

4. Function With Arguments and With Return Value


Functions that have arguments and some return value.

You might also like