SlideShare a Scribd company logo
1 of 23
Functions
GROUP A ‘EVEREST’
Anil Pokhrel
Amit Budachhetri
Ajit Pudasaini
Rikriti Koirala
Roji shrestha
Puja Neupane
Contents
• Introduction to function
• Definition of functions
• Return value and their types
• Function calls
• Function declaration
• Category of function
• Nesting of function
• Recursion
• Passing array to functions
• Passing 2 D array to the function
• Passing string to functions
Functions in C programming
• Depending on whether a function is defined
by the user or already included in C compilers,
there are two types of functions in C
programming
• There are two types of functions in C
programming:
• Standard library functions
• User defined functions
•
Standard library functions
• The standard library functions are built-in functions in
C programming to handle tasks such as mathematical
computations, I/O processing, string handling etc.
• These functions are defined in the header file. When
you include the header file, these functions are
available for use. For example:
• The printf() is a standard library function to send
formatted output to the screen (display output on the
screen). This function is defined in "stdio.h" header file.
• There are other numerous library functions defined
under "stdio.h", such as scanf(), fprintf(), getchar() etc.
Once you include "stdio.h" in your program, all these
functions are available for use.
User defined function
• C allow programmers to define functions. Such
functions created by the user are called user-
defined functions
• Advantages of user-defined function
• The program will be easier to understand,
maintain and debug.
• Reusable codes that can be used in other
programs
• A large program can be divided into smaller
modules. Hence, a large project can be divided
among many programmers
Introduction of user defined Functions
• A function is self contained block of codes that programs
some specific well defined tasks
Example:
void message()
{
printf (“nThis is inside function message”);
}
void main()
{
printf(“This is in main before function call”);
message();
printf(“nthis is after a function call”);
}
Function declaration/ prototype
• It provides:
1. The name of the function
2. Specifies the type of value to be returned
3. Provides the number and type of argument
that must be supplied to the function
4. Facilate error checking between calls to a
function and the corresponding function
definition
Function definition
• The function definition is similar to the
declaration but there is no semicolon
• The first line of the function definition is
known as function declarator that is followed
by function body
• The declarator and the prototype must be
same function name number of arguments,
argument types and return type
Syntax:
return_type function name(type1 arg1,type2
arg2……….typen argn)
{
body of function;
}
WHERE,
return_type= data type being returned
function name= name of the function
type1,type2,……typen represents the data types of the
arguments arg1,arg2,………argn
• Suppose, you need to create a circle and color
it depending upon the radius and color. You
can create two functions to solve this
problem:
• createCircle() function
• color() function
Function example
#include<stdio.h>
#include<conio.h>
int rectangle(int lenghth, int breath)
void main()
{
int a, l, b;
scanf(“%d %d”,&l,&b);
a=rectangle(l,b)
printf(“area=%d”,a);
getch();
}
int rectangle(int length,int breath)
{
int area;
area=length*breadth;
return(area);
}
Return statement
• One of the main feature of function is that it can
return a value to the calling function
• In order for a function to return a value to the
calling function, the function should have return
statement
• This statement comprises of the keyword called
return,followed by the value to be returned
• This value may be a variable constant or even
another function call
Execution of return statement
• When a return statement is executed,it
immediately transfers the control back to the
calling program
• A function call can return only a single value at a
time
• As soon as the return statement is executed the
function terminates if the function doesn’t return
any value
• In this condition it is not necessary to include the
return statement in the function
Types of function
Function with no arguments and no
return value
• When a function has no arguments, it doesnot
receive any data from the calling function
• When it doesnot return any value, the calling
function `doesnot receive any data from the
called function
• So there is no data transfer between calling
function and called function
No arguments passed but a return
value
• It may be the occasion where we may need to
design function that may not take any
arguments
• However it returns a value to the calling
function
• Typically we have getchar function declared in
header file<stdio.h>
• Getchar function has no parameters but it
returns an integer type data that represents a
character
Argument passed and no return
values
• Here function value receives data from the
calling function through arguments
• However it does not send back any value
• Rather it displays the results of calculations at
the terminal
Nesting of functions
• If we are calling any function inside another
function call is known as nesting function call.
• Sometime it converts a difficult program in
easy one.
• Main can call function1 which calls function2
which calls function3…………. and So on
• Nesting of function can be done deeply to a
large limit
• Find the maximum number among five
different integers using nested function call:
• int max(int x,int y){return x>y?x:y;}
• void main(){
• int m;
• m=max(max(4,max(11,6)),max(10,5));
• printf("%d",m);
• getch();
• }
Recursion
• Recursion is a programming technique that allows
the programmer to express operations in terms
of themselves
• This takes the form of a function that calls itself
• A useful way to think of recursive functions is to
imagine them as a process being performed
where one of the instructions is to "repeat the
process"
• This makes it sound very similar to a loop
because it repeats the same code, and in some
ways it is similar to looping
Conclusion
• A return statement is required if the return
type is anything other than void
• If the function doesnot return any value the
return type must be declared void
• Function returns integer value by default
• A function definition can be placed either
after or before the main function
Reference
• Google.com
• E.Balaguruswamy- Programming in ANSI
• Teacher’s notes (MR.LOK PRAKASH
PANDEY)
22
23

More Related Content

What's hot (20)

Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Strings in c
Strings in cStrings in c
Strings in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
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 Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Types of function call
Types of function callTypes of function call
Types of function call
 

Similar to Function in C Programming

CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxGebruGetachew2
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2sumitbardhan
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxSKUP1
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxLECO9
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdfManiMala75
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdfsantosh147365
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptxYagna15
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxsarthakgithub
 

Similar to Function in C Programming (20)

CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Functions
FunctionsFunctions
Functions
 
Functions
FunctionsFunctions
Functions
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
Function
FunctionFunction
Function
 
Function
Function Function
Function
 
Functions
FunctionsFunctions
Functions
 
Python functions
Python functionsPython functions
Python functions
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Lecture6
Lecture6Lecture6
Lecture6
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptx
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
 

More from Anil Pokhrel

Internet and intranet
Internet and intranetInternet and intranet
Internet and intranetAnil Pokhrel
 
Measure of dispersion
Measure of dispersionMeasure of dispersion
Measure of dispersionAnil Pokhrel
 
Correlation and regression
Correlation and regressionCorrelation and regression
Correlation and regressionAnil Pokhrel
 
Correlation analysis
Correlation analysis Correlation analysis
Correlation analysis Anil Pokhrel
 
2 dimension array in programms
2 dimension array in programms2 dimension array in programms
2 dimension array in programmsAnil Pokhrel
 
Priority scheuling
Priority scheuling Priority scheuling
Priority scheuling Anil Pokhrel
 
Operating system file system
Operating system file systemOperating system file system
Operating system file systemAnil Pokhrel
 
object oriented programming OOP
object oriented programming OOPobject oriented programming OOP
object oriented programming OOPAnil Pokhrel
 
Numerical method runge kutta method
Numerical method runge kutta methodNumerical method runge kutta method
Numerical method runge kutta methodAnil Pokhrel
 
Management profile ppt
Management profile pptManagement profile ppt
Management profile pptAnil Pokhrel
 
Bus and memory transfer
Bus and memory transferBus and memory transfer
Bus and memory transferAnil Pokhrel
 
Computer architecture data representation
Computer architecture  data representationComputer architecture  data representation
Computer architecture data representationAnil Pokhrel
 
Management and leadership skills
Management and leadership skillsManagement and leadership skills
Management and leadership skillsAnil Pokhrel
 
color detection using open cv
color detection using open cvcolor detection using open cv
color detection using open cvAnil Pokhrel
 
Client-server technology in web design
Client-server technology in web designClient-server technology in web design
Client-server technology in web designAnil Pokhrel
 
Software Engineering requirements
Software Engineering requirementsSoftware Engineering requirements
Software Engineering requirementsAnil Pokhrel
 
I WAY (SUPER HIGHWAY INFORMATION)
I WAY (SUPER HIGHWAY INFORMATION)I WAY (SUPER HIGHWAY INFORMATION)
I WAY (SUPER HIGHWAY INFORMATION)Anil Pokhrel
 

More from Anil Pokhrel (20)

System software
System softwareSystem software
System software
 
Internet and intranet
Internet and intranetInternet and intranet
Internet and intranet
 
Measure of dispersion
Measure of dispersionMeasure of dispersion
Measure of dispersion
 
Correlation and regression
Correlation and regressionCorrelation and regression
Correlation and regression
 
Correlation analysis
Correlation analysis Correlation analysis
Correlation analysis
 
2 dimension array in programms
2 dimension array in programms2 dimension array in programms
2 dimension array in programms
 
Priority scheuling
Priority scheuling Priority scheuling
Priority scheuling
 
Operating system file system
Operating system file systemOperating system file system
Operating system file system
 
object oriented programming OOP
object oriented programming OOPobject oriented programming OOP
object oriented programming OOP
 
Numerical method runge kutta method
Numerical method runge kutta methodNumerical method runge kutta method
Numerical method runge kutta method
 
Management profile ppt
Management profile pptManagement profile ppt
Management profile ppt
 
Impact of error
Impact of errorImpact of error
Impact of error
 
Control statement
Control statementControl statement
Control statement
 
Bus and memory transfer
Bus and memory transferBus and memory transfer
Bus and memory transfer
 
Computer architecture data representation
Computer architecture  data representationComputer architecture  data representation
Computer architecture data representation
 
Management and leadership skills
Management and leadership skillsManagement and leadership skills
Management and leadership skills
 
color detection using open cv
color detection using open cvcolor detection using open cv
color detection using open cv
 
Client-server technology in web design
Client-server technology in web designClient-server technology in web design
Client-server technology in web design
 
Software Engineering requirements
Software Engineering requirementsSoftware Engineering requirements
Software Engineering requirements
 
I WAY (SUPER HIGHWAY INFORMATION)
I WAY (SUPER HIGHWAY INFORMATION)I WAY (SUPER HIGHWAY INFORMATION)
I WAY (SUPER HIGHWAY INFORMATION)
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

Function in C Programming

  • 1. Functions GROUP A ‘EVEREST’ Anil Pokhrel Amit Budachhetri Ajit Pudasaini Rikriti Koirala Roji shrestha Puja Neupane
  • 2. Contents • Introduction to function • Definition of functions • Return value and their types • Function calls • Function declaration • Category of function • Nesting of function • Recursion • Passing array to functions • Passing 2 D array to the function • Passing string to functions
  • 3. Functions in C programming • Depending on whether a function is defined by the user or already included in C compilers, there are two types of functions in C programming • There are two types of functions in C programming: • Standard library functions • User defined functions •
  • 4. Standard library functions • The standard library functions are built-in functions in C programming to handle tasks such as mathematical computations, I/O processing, string handling etc. • These functions are defined in the header file. When you include the header file, these functions are available for use. For example: • The printf() is a standard library function to send formatted output to the screen (display output on the screen). This function is defined in "stdio.h" header file. • There are other numerous library functions defined under "stdio.h", such as scanf(), fprintf(), getchar() etc. Once you include "stdio.h" in your program, all these functions are available for use.
  • 5. User defined function • C allow programmers to define functions. Such functions created by the user are called user- defined functions • Advantages of user-defined function • The program will be easier to understand, maintain and debug. • Reusable codes that can be used in other programs • A large program can be divided into smaller modules. Hence, a large project can be divided among many programmers
  • 6. Introduction of user defined Functions • A function is self contained block of codes that programs some specific well defined tasks Example: void message() { printf (“nThis is inside function message”); } void main() { printf(“This is in main before function call”); message(); printf(“nthis is after a function call”); }
  • 7. Function declaration/ prototype • It provides: 1. The name of the function 2. Specifies the type of value to be returned 3. Provides the number and type of argument that must be supplied to the function 4. Facilate error checking between calls to a function and the corresponding function definition
  • 8. Function definition • The function definition is similar to the declaration but there is no semicolon • The first line of the function definition is known as function declarator that is followed by function body • The declarator and the prototype must be same function name number of arguments, argument types and return type
  • 9. Syntax: return_type function name(type1 arg1,type2 arg2……….typen argn) { body of function; } WHERE, return_type= data type being returned function name= name of the function type1,type2,……typen represents the data types of the arguments arg1,arg2,………argn
  • 10. • Suppose, you need to create a circle and color it depending upon the radius and color. You can create two functions to solve this problem: • createCircle() function • color() function
  • 11. Function example #include<stdio.h> #include<conio.h> int rectangle(int lenghth, int breath) void main() { int a, l, b; scanf(“%d %d”,&l,&b); a=rectangle(l,b) printf(“area=%d”,a); getch(); } int rectangle(int length,int breath) { int area; area=length*breadth; return(area); }
  • 12. Return statement • One of the main feature of function is that it can return a value to the calling function • In order for a function to return a value to the calling function, the function should have return statement • This statement comprises of the keyword called return,followed by the value to be returned • This value may be a variable constant or even another function call
  • 13. Execution of return statement • When a return statement is executed,it immediately transfers the control back to the calling program • A function call can return only a single value at a time • As soon as the return statement is executed the function terminates if the function doesn’t return any value • In this condition it is not necessary to include the return statement in the function
  • 15. Function with no arguments and no return value • When a function has no arguments, it doesnot receive any data from the calling function • When it doesnot return any value, the calling function `doesnot receive any data from the called function • So there is no data transfer between calling function and called function
  • 16. No arguments passed but a return value • It may be the occasion where we may need to design function that may not take any arguments • However it returns a value to the calling function • Typically we have getchar function declared in header file<stdio.h> • Getchar function has no parameters but it returns an integer type data that represents a character
  • 17. Argument passed and no return values • Here function value receives data from the calling function through arguments • However it does not send back any value • Rather it displays the results of calculations at the terminal
  • 18. Nesting of functions • If we are calling any function inside another function call is known as nesting function call. • Sometime it converts a difficult program in easy one. • Main can call function1 which calls function2 which calls function3…………. and So on • Nesting of function can be done deeply to a large limit
  • 19. • Find the maximum number among five different integers using nested function call: • int max(int x,int y){return x>y?x:y;} • void main(){ • int m; • m=max(max(4,max(11,6)),max(10,5)); • printf("%d",m); • getch(); • }
  • 20. Recursion • Recursion is a programming technique that allows the programmer to express operations in terms of themselves • This takes the form of a function that calls itself • A useful way to think of recursive functions is to imagine them as a process being performed where one of the instructions is to "repeat the process" • This makes it sound very similar to a loop because it repeats the same code, and in some ways it is similar to looping
  • 21. Conclusion • A return statement is required if the return type is anything other than void • If the function doesnot return any value the return type must be declared void • Function returns integer value by default • A function definition can be placed either after or before the main function
  • 22. Reference • Google.com • E.Balaguruswamy- Programming in ANSI • Teacher’s notes (MR.LOK PRAKASH PANDEY) 22
  • 23. 23