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

Presentation 13

The document provides an overview of functions in C programming, including their types, definitions, prototypes, and usage. It discusses the advantages and disadvantages of using functions, as well as real-world applications. The conclusion emphasizes the importance of functions in creating modular and maintainable code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Presentation 13

The document provides an overview of functions in C programming, including their types, definitions, prototypes, and usage. It discusses the advantages and disadvantages of using functions, as well as real-world applications. The conclusion emphasizes the importance of functions in creating modular and maintainable code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

EASWARI ENGINEERING COLLEGE

(AUTONOMOUS)
RAMAPURAM CHENNAI -600089

SUBJECT NAME : FOUNDATION FOR PROBLEM SOLVING USING C


SUBJECT CODE : 191CSO604T

FUNCTIONS IN C PROGRAMMING
TEAM MEMBERS

 MADHAVA PRASAD.V – 310622106074


 NAVEIN.P.A -- 310622106096
 NETRA SRINIVASAN – 310622106098
 NITHYASHREE.V – 310622106099
 RITHIKAA.D - 310622106121
DATE : 02/04/2025
AGENDA

• Introduction • Return Statement

• Working of functions in C • Illustration Program

• Function Prototype • Advantages and Disadvantages of Functions

• Function Definition • Conclusion

• Function Call
INTRODUCTION

• Functions are reusable blocks of code.


• Help in modular programming.
• Improve readability and debugging.

• 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

• Definition: A function prototype is a declaration that tells the compiler


about a function before its actual definition.
• Syntax:
• Return type function_name(parameter_list);

• 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;
• } }

• Usage: greet(); • Usage: int num = getNumber();


3. With Parameters & Without Return Value4. With Parameters & With Return
Takes input but does not return a value. Value
• Example: Takes input and returns a value.
• void displaySum(int a, int b) { • Example:
• printf("Sum = %d\n", a + b); int add(int x, int y) {
return x + y;
•} }

• Usage: displaySum(5, 7); • Usage: int result = add(5, 7);


EXAMPLE PROGRAM
Simple Addition in C
#include <stdio.h>
// Function prototype
int add(int, int);
int main() {
int num1 = 10, num2 = 20, sum;
sum = add(num1, num2); // Function call
printf("Sum = %d", sum);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b; // Return statement
}
ADVANTAGES OF USING FUNCTIONS

• 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.

• Functions have limited access to variables declared outside their scopes.

• Recursive Functions can be less efficient.


REAL WORLD USE OF CASE FUNCTIONS

• 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

• Functions make programs modular, reusable, and easy to debug.


• Understanding prototypes, definitions, calls, and returns is essential.
• Different types of functions provide flexibility in coding.
• Functions improve code organization and maintainability.
REFERENCES
• https://www.geeksforgeeks.org/functions-in-c/
• https://www.tutorialspoint.com/cprogramming/c_functions.htm
• https://www.programiz.com/c-programming/c-functions
• https://www.w3schools.com/c/c_functions.php
THANK YOU

You might also like