Presentation 13
Presentation 13
(AUTONOMOUS)
RAMAPURAM CHENNAI -600089
FUNCTIONS IN C PROGRAMMING
TEAM MEMBERS
• Function Call
INTRODUCTION
• Types of functions:
• Library Functions (e.g., printf(), scanf())
• User-Defined Functions
WORKING OF FUNCTIONS IN C
• Declaration of functions
• Definition of functions
• Calling functions
• Execution of functions
• Returning a value
FUNCTION PROTOTYPE
• Example:
int add(int, int);
FUNCTION DEFINITION
•Definition
The function definition contains the actual body of the function.
•Syntax:
•return_type function_name(parameter_list) {
• // function body
}
•Example:
• int add(int a, int b) {
• return a + b;
}
FUNCTION CALL
• Definition
A function is called when it is invoked in the main program.
• Syntax:
function_name(arguments);
• Example:
int sum = add(5, 10);
RETURN STATEMENT
• Definition
The return statement sends back a value from a function to the caller.
• Syntax:
• return value;
• Example:
return a + b;
TYPES OF USER DEFINED FUNCTIONS
1. Without Parameters & Without Return 2. Without Parameters & With Return
Value Value
No input, no return value. No input, but returns a value.
• Example:
• Example:
• void greet() {
int getNumber() {
• printf("Hello!\n");
return 10;
• } }
• Code reusability
• Reduces redundancy
• Increases program modularity
• Enhances readability and debugging
DISADVANTAGES OF FUNCTIONS
• Cannot return multiple values.
• Memory and time overhead due to stack frame allocation and transfer of
program control.
• Mathematical Computations
(e.g., calculator functions)
• File Handling
(e.g., opening, reading, writing files)
• Data Processing
(e.g., sorting, searching)
• Embedded Systems
(e.g., sensor reading functions)
CONCLUSION