0% found this document useful (0 votes)
2 views

Function

Uploaded by

Arman Danesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Function

Uploaded by

Arman Danesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Function

A function is a block of code or statements which only runs when it is


called.

Functions are used to perform certain actions, and they are important for
reusing code: Define the code once, and use it many times.
Library Functions User-Defined Functions

● Also referred to as These are the functions that a


predefined functions, developer or the user declares,
● library functions are already defines, and calls in a program.
defined in the C libraries
Printf(), scanf(), ceil(), and floor()
are examples of library functions.
● Function declaration A function must be declared globally in a c program to
tell the compiler about the function name, function parameters, and return
type.

return_type function_name (argument list);

● Function call a function call is calling a function to be executed by the


compiler. You can call the function at any point in the entire program.
need to pass as many arguments of the same data type as mentioned while
declaring the function.

function_name (argument_list)
● Function Definition It is defining the actual statements that the compiler
will execute upon calling the function. You can think of it as the body of the
function.
return_type function_name (argument list) {function
body;}
Different aspects of function calling

● function without arguments and without return value


● function without arguments and with return value
● function with arguments and without return value
● function with arguments and with return value
Why Do We Need Functions in C Programming?

● By using functions, we can avoid rewriting same logic/code again and again in a
program.
● We can call C functions any number of times in a program and from any place in
a program.
● We can track a large C program easily when it is divided into multiple functions.
● Enables reusability and reduces redundancy
● Makes a code modular
● Provides abstraction functionality
● The program becomes easy to understand and manage
● Breaks an extensive program into smaller and simpler pieces

You might also like