Functions in C
⏱ Estimated reading time: 2 min
A function is a block of code that performs a specific task.
Functions help in modular programming, code reuse, and readability.
Types of Functions
-
Library Functions
-
User-Defined Functions
1. Library Functions
Predefined functions provided by C libraries.
Examples:
-
printf() -
scanf() -
strlen() -
sqrt()
2. User-Defined Functions
Functions written by the programmer.
Structure of a Function
Function Declaration (Prototype)
Function Definition
Function Call
Example Program
Components of a Function
-
Return type – Type of value returned
-
Function name – Identifier
-
Parameters – Values passed to function
-
Function body – Statements to execute
Types of User-Defined Functions
Based on arguments and return value:
-
No arguments, no return value
-
Arguments, no return value
-
No arguments, return value
-
Arguments and return value
Call by Value
-
Actual value is passed to function
-
Changes do not affect original variable
Recursion
A function calling itself.
Advantages of Functions
-
Code reusability
-
Easy debugging
-
Better readability
-
Reduced program size
Summary
-
Functions divide a program into modules
-
main()is the starting function -
Functions can return values
-
Recursion is supported
Register Now
Share this Post
← Back to Tutorials