FUNCTIONS
Bachelor of Information Technology I Semester
Amrit Dangi
Binayak Sijapati
Sushant Khadka
CONTENTS
• Introduction to Function 1
• Library Function 2
• User define Function 3
• Types of Functions(4-types) 4-8
• Conclusion 9
INTRODUCTION
• A function is a self-contained subprogram meant to do well-defined
task.
• It helps to divide a complex program into chunks, each of which
performs specific tasks.
• Use of functions avoids repetition of code & helps in organizing
code making it reusable & easier to debug.
1
LIBRARY FUNCTION
• Predefined functions provided by C standard library.
• Declared in header files e.g.stdio.h, string.h.
• Can be reused across multiple programs without rewriting the code.
• Cannot be modified by users.
• E.g.. printf() , scanf(), strlen() etc.
2
USER DEFINED FUNCTIONS
• Defined by users for specific tasks.
• Declared in the program by users.
• Need to be rewritten or copied into other programs for reuse.
• Can be fully customized by users as requirements.
• E.g. add(), factorial(), swapArray() etc.
3
TYPES OF FUNCTIONS
1. With no argument and no return value
2. With no arguments and a return value
3. With arguments and no return value
4. With arguments and a return value
4
1.No Argument and No Return
• The function does not take any input parameters.
• The function does not return any value (void is used as the return type).
Syntax
void functionName() {
// Function code
}
5
2.No Argument and a Return Value
• The function does not take any input parameters
• The function returns a result using the return statement.
Syntax
returnType functionName() {
// Code
return value;
}
6
3.Argument and No Return Value
• The function accepts input parameters
• The function performs an operation but does not return anything (void is used)
Syntax
void functionName(dataType param1, dataType param2, ...) {
// Function body (performs an operation)
}
7
4. Argument and a Return Value
• The function accepts input parameters.
• The function processes the inputs and returns a result using return.
Syntax
returnType functionName(dataType param1, dataType param2, ...) {
// Function logic
return value;
}
8
CONCLUSION
By effectively using functions, we can write efficient, structured, and maintainable C
programs. Mastering functions helps in building complex applications while keeping
the code clean and manageable.
9
QUESTIONS/QUERIES…
10