SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
FUNCTIONS IN C
FUNCTIONS
• A function is a group of statements that together perform a task.
• Every C program has at least one function, which is main(), and all
the most trivial programs can define additional functions.
• A function declaration tells the compiler about a function's name,
return type, and parameters.
• A function definition provides the actual body of the function.
TYPES OF FUNCTIONS
• Predefined standard library functions
1. Standard library functions are also known as built-in functions. Functions
such as puts(), gets(), printf(), scanf() etc are standard library functions.
2. These functions are already defined in header files (files with .h
extensions are called header files such as stdio.h), so we just call them
whenever there is a need to use them.
• User Defined functions
1. The functions that we create in a program are known as user defined
functions or in other words you can say that a function created by user is
known as user defined function.
DEFINING A FUNCTION
• A function definition in C programming consists of a function header and
a function body. Here are all the parts of a function −
• Return Type − A function may return a value. The return_type is the data
type of the value the function returns.
• Function Name − This is the actual name of the function. The function
name and the parameter list together constitute the function signature.
• Parameters − A parameter is like a placeholder. When a function is
invoked, you pass a value to the parameter.
• Function Body − The function body contains a collection of statements that
define what the function does.
EXAMPLE
FUNCTION DECLARATION
• A function declaration tells the compiler about a function name and
how to call the function.
• The actual body of the function can be defined separately.
• Function declaration is required when you define a function in one
source file and you call that function in another file.
• A function declaration has the following parts −
FUNCTION CALLING
• While creating a C function, you give a definition of what the function
has to do.
• To use a function, you will have to call that function to perform the
defined task.
• When a program calls a function, the program control is transferred to
the called function.
• A called function performs a defined task and when its return
statement is executed or when its function-ending closing brace is
reached, it returns the program control back to the main program.
FUNCTION ARGUMENTS
• While calling a function, there are two ways in which arguments can
be passed to a function −
FUNCTION SYNTAX
/* function declaration */
int max(int num1, int num2);
int main ()
/* local variable definition */
int a = 100;
int b = 200;
int ret;
/* calling a function to get max value */
ret = max(a, b);
printf( "Max value is : %dn", ret );
return 0;
}
/* function returning the max between
two numbers */
int max(int num1, int num2) {
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Few Points to Note regarding functions in C:
1. main() in C program is also a function.
2. Each C program must have at least one function, which is main()
3. There is no limit on number of functions; A C program can have any
number of functions.
4. A function can call itself and it is known as “Recursion“.

More Related Content

PPTX
Module 3-Functions
PPTX
unit_2 (1).pptx
PDF
unit3 part2 pcds function notes.pdf
PPTX
PPTX
functions in the c programming and the examples
PPTX
Lecture_5_-_Functions_in_C_Detailed.pptx
PPTX
CH.4FUNCTIONS IN C (1).pptx
PPTX
Functions and structure in programming c
Module 3-Functions
unit_2 (1).pptx
unit3 part2 pcds function notes.pdf
functions in the c programming and the examples
Lecture_5_-_Functions_in_C_Detailed.pptx
CH.4FUNCTIONS IN C (1).pptx
Functions and structure in programming c

Similar to FUNCTIONS IN C.pptx (20)

PPTX
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
PPTX
user-definedfunctions-converted.pptx
PPTX
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
PPTX
FUNCTIONengineeringtechnologyslidesh.pptx
PPTX
unit_2.pptx
PPTX
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
PPTX
Detailed concept of function in c programming
PDF
Functions in c mrs.sowmya jyothi
PPTX
Functions in c language
PPTX
Functions in c language
PPT
C FUNCTIONS
PPT
c-Functions power point presentation on c functions
PDF
User_Defined_Functions_ppt_slideshare.
PPT
User defined functions in C programmig
PPTX
Functions in c
PDF
functionsinc-130108032745-phpapp01.pdf
PPTX
Function C programming
PPTX
The function contains the set of programming statements enclosed by {}  when ...
PPTX
Functions in C.pptx
PPTX
Functions in C.pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
user-definedfunctions-converted.pptx
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
FUNCTIONengineeringtechnologyslidesh.pptx
unit_2.pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Detailed concept of function in c programming
Functions in c mrs.sowmya jyothi
Functions in c language
Functions in c language
C FUNCTIONS
c-Functions power point presentation on c functions
User_Defined_Functions_ppt_slideshare.
User defined functions in C programmig
Functions in c
functionsinc-130108032745-phpapp01.pdf
Function C programming
The function contains the set of programming statements enclosed by {}  when ...
Functions in C.pptx
Functions in C.pptx
Ad

More from SKUP1 (20)

PPTX
serial_busses_i2c.pptx
PPTX
DESIGN PATTERN.pptx
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
C-Programming File-handling-C.pptx
PPTX
Processes, Threads.pptx
PPTX
C-Programming Control statements.pptx
PPTX
Finite State Machine.ppt.pptx
PPTX
cprogramming strings.pptx
PPTX
UNIONS IN C.pptx
PPTX
OPERATORS IN C.pptx
PPTX
cprogramming Structures.pptx
PPTX
C-Programming Function pointers.pptx
PPTX
POINTERS.pptx
PPTX
STACKS AND QUEUES.pptx
PPTX
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
PPTX
C MEMORY MODEL​.pptx
PPTX
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
PPTX
DYNAMIC MEMORY ALLOCATION.pptx
PPTX
COMPILATION PROCESS IN C.pptx
serial_busses_i2c.pptx
DESIGN PATTERN.pptx
INTER PROCESS COMMUNICATION (IPC).pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
C-Programming File-handling-C.pptx
Processes, Threads.pptx
C-Programming Control statements.pptx
Finite State Machine.ppt.pptx
cprogramming strings.pptx
UNIONS IN C.pptx
OPERATORS IN C.pptx
cprogramming Structures.pptx
C-Programming Function pointers.pptx
POINTERS.pptx
STACKS AND QUEUES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C MEMORY MODEL​.pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DYNAMIC MEMORY ALLOCATION.pptx
COMPILATION PROCESS IN C.pptx
Ad

Recently uploaded (20)

PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Sustainable Sites - Green Building Construction
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Well-logging-methods_new................
PPTX
Construction Project Organization Group 2.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Foundation to blockchain - A guide to Blockchain Tech
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
bas. eng. economics group 4 presentation 1.pptx
R24 SURVEYING LAB MANUAL for civil enggi
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
UNIT 4 Total Quality Management .pptx
Lecture Notes Electrical Wiring System Components
Operating System & Kernel Study Guide-1 - converted.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Sustainable Sites - Green Building Construction
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Well-logging-methods_new................
Construction Project Organization Group 2.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

FUNCTIONS IN C.pptx

  • 2. FUNCTIONS • A function is a group of statements that together perform a task. • Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. • A function declaration tells the compiler about a function's name, return type, and parameters. • A function definition provides the actual body of the function.
  • 3. TYPES OF FUNCTIONS • Predefined standard library functions 1. Standard library functions are also known as built-in functions. Functions such as puts(), gets(), printf(), scanf() etc are standard library functions. 2. These functions are already defined in header files (files with .h extensions are called header files such as stdio.h), so we just call them whenever there is a need to use them. • User Defined functions 1. The functions that we create in a program are known as user defined functions or in other words you can say that a function created by user is known as user defined function.
  • 4. DEFINING A FUNCTION • A function definition in C programming consists of a function header and a function body. Here are all the parts of a function − • Return Type − A function may return a value. The return_type is the data type of the value the function returns. • Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature. • Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. • Function Body − The function body contains a collection of statements that define what the function does.
  • 6. FUNCTION DECLARATION • A function declaration tells the compiler about a function name and how to call the function. • The actual body of the function can be defined separately. • Function declaration is required when you define a function in one source file and you call that function in another file. • A function declaration has the following parts −
  • 7. FUNCTION CALLING • While creating a C function, you give a definition of what the function has to do. • To use a function, you will have to call that function to perform the defined task. • When a program calls a function, the program control is transferred to the called function. • A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.
  • 8. FUNCTION ARGUMENTS • While calling a function, there are two ways in which arguments can be passed to a function −
  • 10. /* function declaration */ int max(int num1, int num2); int main () /* local variable definition */ int a = 100; int b = 200; int ret; /* calling a function to get max value */ ret = max(a, b); printf( "Max value is : %dn", ret ); return 0; } /* function returning the max between two numbers */ int max(int num1, int num2) { /* local variable declaration */ int result; if (num1 > num2) result = num1; else result = num2; return result; }
  • 11. Few Points to Note regarding functions in C: 1. main() in C program is also a function. 2. Each C program must have at least one function, which is main() 3. There is no limit on number of functions; A C program can have any number of functions. 4. A function can call itself and it is known as “Recursion“.