SlideShare a Scribd company logo
C FUNCTIONS
Prepared by
TEENA GEORGE(CSE)
Assistant Professor
Adi Shankara Institute of Engineering &
Technology, Kalady
CONTENTS
 Introduction to modular programming/functions
 Elements of functions
 Parameter Vs Argument
 Sample program
2
WHAT IS A FUNCTION ???
 A function is a block of code in C that performs a
specific task.
 Every C program has at least one function, which
is main(), and can define additional functions.
3
NEED FOR FUNCTIONS/BENEFITS OF
FUNCTIONS
 Modular Programming :
 process of subdividing a computer program into
separate sub-programs/modules.
 Easy to built, use and test
 Increase readability
 Reuse the code
 Easy to maintain
 Easy to debug
 The length of a source program can be reduced
4
TYPES OF C FUNCTION
 Standard library functions
 built-in functions in C programming to handle tasks
such as mathematical computations, I/O processing,
string handling etc
 For example, printf() is a standard library function to
send formatted output to the screen defined
in "stdio.h" header file
 Some other examples : scanf(), strlen(), getchar() ,
sqrt(), toupper()
 User defined function
 Functions that we define ourselves to do certain
specific task
5
ELEMENTS OF A FUNCTION
6
C FUNCTIONS
 FUNCTION DECLARATION OR FUNCTION
PROTOTYPING
 FUNCTION CALL
 FUNCTION DEFINITION
7
FUNCTION DECLARATION OR PROTOTYPE
 This statement informs compiler about the function
name, function parameters and return value’s data type.
 Prototype declaration always ends with semicolon.
 If function definition is written above the main function
then ,no need to write prototype declaration
8
FUNCTION DECLARATION OR PROTOTYPE
 Syntax:
 Example:
 int sum(int a, int b);
 int sum(int, int);
 void display();
returntype functioname(argtype name1,....,argtype namen);
9
FUNCTION CALL
 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.
10
FUNCTION CALL
 Syntax:
 Example:
 sum(a,b);
 display();
Functionname(argname1,argname2,....argnamen);
11
FUNCTION DEFINITION
 A function definition consists of a function header and
a function body.
 Function header :- consist of return type,function name,
arguments
 Return Type −
 return_type is the data type of the value the function returns.
 Some functions perform the desired operations without returning
a value(use ‘void’)
 Function Name −
 The function name of user choice following identifier rules
 Parameters −
 Values passed to a function to do the desired task
 Function Body :- contains a set of statements that define
what the function does.
12
FUNCTION DEFINITION
 Syntax:
 Example:
int sum(int a, int b)
{
int c=0;
c=a+b;
printf(“%d”,c);
}
return_type function_name(argument list ) //function header
{
body of the function
return statement
}
13
PARAMETER & ARGUMENTS
 Parameters are temporary variable names within
functions.
 The argument can be thought of as the value that is
assigned to that temporary variable
 Within the function, parameters act as placeholders for
the argument it is passed
 The parameter number and type of declaration and
definition must match.
 Actual parameters :- parameters appearing in
function calls.
 Formal parameters :-parameters appear in function
declarations/definitions 14
SAMPLE PROGRAM
#include <stdio.h>
void sum(int a,int b);
int main()
{
int a,b;
printf("nEnter values for a and b");
scanf("%d%d",&a,&b);
sum(a,b);
return 0;
}
void sum(int a,int b)
{
int c=0;
c=a+b;
printf("n%d + %d = %d",a,b,c);
}
Function Call
Function Definition
Function Declaration
15
REWIND…
 Can you think of a real time example for function?
 Can you remember any 5 built in functions in C ?
 Can you recall the three parts of a function?
 Can you differentiate function declaration and function
definition?
 What is the syntax of a function call statement?
 What do you call the parameters in the call statement?
 You can omit the declaration statement if definition of
function is done at the global declaration section. True
or False?
16
COMING SOON…….
Category of functions
1. Functions with no arguments and no return values
2. Functions with arguments and no return values
3. Functions with arguments and one return values
4. Functions with no arguments and but return a value
5. Function that have multiple return values(work based
on condition)
17
THANKYOU
18

More Related Content

What's hot

Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
C functions
C functionsC functions
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
VC Infotech
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
sruthi yandapalli
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
programmings guru
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
Prabhu Govind
 
C function presentation
C function presentationC function presentation
C function presentation
Touhidul Shawan
 
Function in C and C++
Function in C and C++Function in C and C++
Function in C and C++
Rahul Sahu
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
C structure
C structureC structure
C structure
ankush9927
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
Syed Mustafa
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
Meghaj Mallick
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
Swapnil Yadav
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
Saket Pathak
 
Function
FunctionFunction
Function
Rajat Patel
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Built in function
Built in functionBuilt in function
Built in function
MD. Rayhanul Islam Sayket
 

What's hot (20)

Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
C functions
C functionsC functions
C functions
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Function in c
Function in cFunction in c
Function in c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
C function presentation
C function presentationC function presentation
C function presentation
 
Function in C and C++
Function in C and C++Function in C and C++
Function in C and C++
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
C structure
C structureC structure
C structure
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Function
FunctionFunction
Function
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Built in function
Built in functionBuilt in function
Built in function
 

Similar to C FUNCTIONS

unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
nikshaikh786
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
Sowri Rajan
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
Venkatesh Goud
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
floraaluoch3
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
vekariyakashyap
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
Hattori Sidek
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programming
SayeemAhmed8
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
Manivannan837728
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
Functions
FunctionsFunctions

Similar to C FUNCTIONS (20)

unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Functions
Functions Functions
Functions
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programming
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
Functions
FunctionsFunctions
Functions
 

Recently uploaded

basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 

Recently uploaded (20)

basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 

C FUNCTIONS

  • 1. C FUNCTIONS Prepared by TEENA GEORGE(CSE) Assistant Professor Adi Shankara Institute of Engineering & Technology, Kalady
  • 2. CONTENTS  Introduction to modular programming/functions  Elements of functions  Parameter Vs Argument  Sample program 2
  • 3. WHAT IS A FUNCTION ???  A function is a block of code in C that performs a specific task.  Every C program has at least one function, which is main(), and can define additional functions. 3
  • 4. NEED FOR FUNCTIONS/BENEFITS OF FUNCTIONS  Modular Programming :  process of subdividing a computer program into separate sub-programs/modules.  Easy to built, use and test  Increase readability  Reuse the code  Easy to maintain  Easy to debug  The length of a source program can be reduced 4
  • 5. TYPES OF C FUNCTION  Standard library functions  built-in functions in C programming to handle tasks such as mathematical computations, I/O processing, string handling etc  For example, printf() is a standard library function to send formatted output to the screen defined in "stdio.h" header file  Some other examples : scanf(), strlen(), getchar() , sqrt(), toupper()  User defined function  Functions that we define ourselves to do certain specific task 5
  • 6. ELEMENTS OF A FUNCTION 6
  • 7. C FUNCTIONS  FUNCTION DECLARATION OR FUNCTION PROTOTYPING  FUNCTION CALL  FUNCTION DEFINITION 7
  • 8. FUNCTION DECLARATION OR PROTOTYPE  This statement informs compiler about the function name, function parameters and return value’s data type.  Prototype declaration always ends with semicolon.  If function definition is written above the main function then ,no need to write prototype declaration 8
  • 9. FUNCTION DECLARATION OR PROTOTYPE  Syntax:  Example:  int sum(int a, int b);  int sum(int, int);  void display(); returntype functioname(argtype name1,....,argtype namen); 9
  • 10. FUNCTION CALL  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. 10
  • 11. FUNCTION CALL  Syntax:  Example:  sum(a,b);  display(); Functionname(argname1,argname2,....argnamen); 11
  • 12. FUNCTION DEFINITION  A function definition consists of a function header and a function body.  Function header :- consist of return type,function name, arguments  Return Type −  return_type is the data type of the value the function returns.  Some functions perform the desired operations without returning a value(use ‘void’)  Function Name −  The function name of user choice following identifier rules  Parameters −  Values passed to a function to do the desired task  Function Body :- contains a set of statements that define what the function does. 12
  • 13. FUNCTION DEFINITION  Syntax:  Example: int sum(int a, int b) { int c=0; c=a+b; printf(“%d”,c); } return_type function_name(argument list ) //function header { body of the function return statement } 13
  • 14. PARAMETER & ARGUMENTS  Parameters are temporary variable names within functions.  The argument can be thought of as the value that is assigned to that temporary variable  Within the function, parameters act as placeholders for the argument it is passed  The parameter number and type of declaration and definition must match.  Actual parameters :- parameters appearing in function calls.  Formal parameters :-parameters appear in function declarations/definitions 14
  • 15. SAMPLE PROGRAM #include <stdio.h> void sum(int a,int b); int main() { int a,b; printf("nEnter values for a and b"); scanf("%d%d",&a,&b); sum(a,b); return 0; } void sum(int a,int b) { int c=0; c=a+b; printf("n%d + %d = %d",a,b,c); } Function Call Function Definition Function Declaration 15
  • 16. REWIND…  Can you think of a real time example for function?  Can you remember any 5 built in functions in C ?  Can you recall the three parts of a function?  Can you differentiate function declaration and function definition?  What is the syntax of a function call statement?  What do you call the parameters in the call statement?  You can omit the declaration statement if definition of function is done at the global declaration section. True or False? 16
  • 17. COMING SOON……. Category of functions 1. Functions with no arguments and no return values 2. Functions with arguments and no return values 3. Functions with arguments and one return values 4. Functions with no arguments and but return a value 5. Function that have multiple return values(work based on condition) 17