A function is a block of code that performs a specific task.
Functions help in modular programming, code reuse, and readability.
Library Functions
User-Defined Functions
Predefined functions provided by C libraries.
Examples:
printf()
scanf()
strlen()
sqrt()
Functions written by the programmer.
Return type – Type of value returned
Function name – Identifier
Parameters – Values passed to function
Function body – Statements to execute
Based on arguments and return value:
No arguments, no return value
Arguments, no return value
No arguments, return value
Arguments and return value
Actual value is passed to function
Changes do not affect original variable
A function calling itself.
Code reusability
Easy debugging
Better readability
Reduced program size
Functions divide a program into modules
main() is the starting function
Functions can return values
Recursion is supported
Take quizzes related to this topic and see where you stand!
Start Quiz Now