SlideShare a Scribd company logo
1
Advance Computer Programming(3320702)
CH – 3
Functions
GOVERNMENT POLYTECHNIC,
AHMEDABAD
SHAH DHRUV P. (166170307093)
SHAH HARSH J. (166170307095)
SHAH KUNJ D. (166170307096)
SUBMITTED BY
TOPICS
2
• Functions.
• Prototype.
• Nested Functions.
• Types of Functions.
• Recursion.
• Call By Value & Call By Refrence.
• Function & Array.
• Storage Classes.
FUNCTIONS
3
• Defination :- A function is a self contained block of statements
that performs a co-herent task of some kind.
• Every C program can be thought of as a collection of this
function.
• Functions are used when user wants to call a multiple times.
• Functions returns value as either 1 or 0.
• A void function will never return a value.
3.1
PROTOTYPE
4
• Prototype is used when a user wants to define a function after the main()
function.
• The syntax for prototype inside main() function is:-
data_type function_name(data_type1,data_type 2,……data_type n);
3.2
NESTED FUNCTIONS
5
• If a function makes a call to another function in its body , then it
is called Nested Function.
• For example while making a program of sorting an array , user
uses the swap function inside the function of sorting.
3.3
EXAMPLE:-
6
`
void sort (int a[ ],int n)
{ int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i] > a[j])
{
swap( a[i] , a[j] )
}
}
}
}
TYPES OF FUNCTIONS
7
Function
Library
Functions
User Defined
Functions
3.4
LIBRARY FUNCTIONS
8
• Library Functions are the predefined functions in C language.
• These are the functions which can’t be changed.
• The example of these functions is main().
USER DEFINED FUNCTIONS
9
• User defined Functions are functions which are made by the user
in a C program and called in main() function.
• User defined functions are of 4 types:-
1. No Return value and No Argument.
2. With Return value and No Argument.
3. No Return value and With Argument.
4. With Return value and With Argument.
NO RETURN VALUE AND NO ARGUMENT
10
• Syntax for declaration :-
void Function_name()
{
BODY
}
• Syntax for calling:-
Function_name();
NO RETURN VALUE AND WITH
ARGUMENT
11
• Syntax for declaration :-
void Function_name(argument 1,
argument2…….argument n)
{
BODY
}
• Syntax for calling:-
Function_name(argument 1,argument 2,
……..argument n);
WITH RETURN VALUE AND NO
ARGUMENT
12
• Syntax for declaration :-
data_type Function_name()
{
BODY
}
• Syntax for calling:-
data_type variable_name=Function_name();
WITH RETURN VALUE AND WITH
ARGUMENT
13
• Syntax for declaration :-
data_type variable=
Function_name(argument 1,argument 2……argument n)
{
BODY
}
• Syntax for calling:-
data_type variable_name=Function_name(argument 1,
argument 2……..argument n);
RECURSION
14
• When a function calls itself it is called Recursion.
• Recursion is used in finding factorial of number , Fibonacci
sequence , etc.
• Advantages of recursion are:-
1. Unnecessary use of loop can be stopped.
2. Returning of unnecessary value can be stopped.
3.5
RECURSION
15
• Disadvantages of recursion :-
1. If condition is necessary to return a value.
2. Sometimes it is difficult to trace the flow in recursion.
CALL BY VALUE
16
• While passing the argument in a function if the parameter
passed is the value , it is called call by value.
• For example :- While making a function of swapping , the value
passed as parameter is value of a variable ,it is called call by
value.
3.6
CALL BY REFERENCE
17
• While passing the argument in a function if the parameter
passed is the reference variable i.e. address of variable, it is
called call by reference.
• For example :- While making a function of swapping , the value
passed as parameter is address of a variable ,it is called call by
reference.
FUNCTION & ARRAY
18
• In function user can also pass the array as a parameter .
• When array is passed as a parameter in a function , actually
the address of the first element in array is passed .
• Here , user has to take one more parameter with the array as
the total number of elements in array.
3.7
STORAGE CLASSES
19
3.8
Storage
Classes
Scope of
variables
Life of
variables
SCOPE OF VARIABLES
20
• Scope of Variables can divided into 2 types:-
1. Local Variables.
2. Global Variables.
1. Local Variables:- Scope of local variables is limited upto a
function block (i.e. within the curly braces).
SCOPE OF VARIABLES
21
2. Global Variables :- Global Variables has no such boundary limit .
The Global Variables can be accessed from any where in the C
program
These variables are declared above the main() function.
LIFE OF VARIABLE
22
• The life of local variable is limited upto the curly braces while
the life of Global Variable is till the program termination as it is
declared only once in the program.
• Register Variable :- Register variables are used to execute the
program faster.
• The syntax to declare Register variable is:-
register data_type variable_name;

More Related Content

What's hot

Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
MOHIT DADU
 
Function and types
Function  and typesFunction  and types
Function and types
Sherin Fathima
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Functions
FunctionsFunctions
Functions
Septi Ratnasari
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
Array Cont
Array ContArray Cont
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
Khadija Parween
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
Appili Vamsi Krishna
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
SaraswathiTAsstProfI
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
LISP:Control Structures In Lisp
LISP:Control Structures In LispLISP:Control Structures In Lisp
LISP:Control Structures In Lisp
DataminingTools Inc
 

What's hot (20)

Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
Function and types
Function  and typesFunction  and types
Function and types
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Functions
FunctionsFunctions
Functions
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 
Array Cont
Array ContArray Cont
Array Cont
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Function in c++
Function in c++Function in c++
Function in c++
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
functions of C++
functions of C++functions of C++
functions of C++
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
LISP:Control Structures In Lisp
LISP:Control Structures In LispLISP:Control Structures In Lisp
LISP:Control Structures In Lisp
 

Similar to functions

Functions
FunctionsFunctions
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Python functions
Python functionsPython functions
Python functions
Prof. Dr. K. Adisesha
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
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 C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Functions
FunctionsFunctions
Functions
Online
 
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
sumitbardhan
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
GebruGetachew2
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
arvdexamsection
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
AkshayKumarK14
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Functions
Functions Functions
Functions
Praneeth960856
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 

Similar to functions (20)

Functions
FunctionsFunctions
Functions
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Python functions
Python functionsPython functions
Python functions
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Functions
FunctionsFunctions
Functions
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Functions
FunctionsFunctions
Functions
 
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
Functions in cFunctions in c
Functions in c
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Functions
Functions Functions
Functions
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 

Recently uploaded

UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
amsjournal
 
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
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
shivani5543
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
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
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
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
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 

Recently uploaded (20)

UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
 
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
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
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.
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
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
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 

functions

  • 1. 1 Advance Computer Programming(3320702) CH – 3 Functions GOVERNMENT POLYTECHNIC, AHMEDABAD SHAH DHRUV P. (166170307093) SHAH HARSH J. (166170307095) SHAH KUNJ D. (166170307096) SUBMITTED BY
  • 2. TOPICS 2 • Functions. • Prototype. • Nested Functions. • Types of Functions. • Recursion. • Call By Value & Call By Refrence. • Function & Array. • Storage Classes.
  • 3. FUNCTIONS 3 • Defination :- A function is a self contained block of statements that performs a co-herent task of some kind. • Every C program can be thought of as a collection of this function. • Functions are used when user wants to call a multiple times. • Functions returns value as either 1 or 0. • A void function will never return a value. 3.1
  • 4. PROTOTYPE 4 • Prototype is used when a user wants to define a function after the main() function. • The syntax for prototype inside main() function is:- data_type function_name(data_type1,data_type 2,……data_type n); 3.2
  • 5. NESTED FUNCTIONS 5 • If a function makes a call to another function in its body , then it is called Nested Function. • For example while making a program of sorting an array , user uses the swap function inside the function of sorting. 3.3
  • 6. EXAMPLE:- 6 ` void sort (int a[ ],int n) { int i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i] > a[j]) { swap( a[i] , a[j] ) } } } }
  • 8. LIBRARY FUNCTIONS 8 • Library Functions are the predefined functions in C language. • These are the functions which can’t be changed. • The example of these functions is main().
  • 9. USER DEFINED FUNCTIONS 9 • User defined Functions are functions which are made by the user in a C program and called in main() function. • User defined functions are of 4 types:- 1. No Return value and No Argument. 2. With Return value and No Argument. 3. No Return value and With Argument. 4. With Return value and With Argument.
  • 10. NO RETURN VALUE AND NO ARGUMENT 10 • Syntax for declaration :- void Function_name() { BODY } • Syntax for calling:- Function_name();
  • 11. NO RETURN VALUE AND WITH ARGUMENT 11 • Syntax for declaration :- void Function_name(argument 1, argument2…….argument n) { BODY } • Syntax for calling:- Function_name(argument 1,argument 2, ……..argument n);
  • 12. WITH RETURN VALUE AND NO ARGUMENT 12 • Syntax for declaration :- data_type Function_name() { BODY } • Syntax for calling:- data_type variable_name=Function_name();
  • 13. WITH RETURN VALUE AND WITH ARGUMENT 13 • Syntax for declaration :- data_type variable= Function_name(argument 1,argument 2……argument n) { BODY } • Syntax for calling:- data_type variable_name=Function_name(argument 1, argument 2……..argument n);
  • 14. RECURSION 14 • When a function calls itself it is called Recursion. • Recursion is used in finding factorial of number , Fibonacci sequence , etc. • Advantages of recursion are:- 1. Unnecessary use of loop can be stopped. 2. Returning of unnecessary value can be stopped. 3.5
  • 15. RECURSION 15 • Disadvantages of recursion :- 1. If condition is necessary to return a value. 2. Sometimes it is difficult to trace the flow in recursion.
  • 16. CALL BY VALUE 16 • While passing the argument in a function if the parameter passed is the value , it is called call by value. • For example :- While making a function of swapping , the value passed as parameter is value of a variable ,it is called call by value. 3.6
  • 17. CALL BY REFERENCE 17 • While passing the argument in a function if the parameter passed is the reference variable i.e. address of variable, it is called call by reference. • For example :- While making a function of swapping , the value passed as parameter is address of a variable ,it is called call by reference.
  • 18. FUNCTION & ARRAY 18 • In function user can also pass the array as a parameter . • When array is passed as a parameter in a function , actually the address of the first element in array is passed . • Here , user has to take one more parameter with the array as the total number of elements in array. 3.7
  • 20. SCOPE OF VARIABLES 20 • Scope of Variables can divided into 2 types:- 1. Local Variables. 2. Global Variables. 1. Local Variables:- Scope of local variables is limited upto a function block (i.e. within the curly braces).
  • 21. SCOPE OF VARIABLES 21 2. Global Variables :- Global Variables has no such boundary limit . The Global Variables can be accessed from any where in the C program These variables are declared above the main() function.
  • 22. LIFE OF VARIABLE 22 • The life of local variable is limited upto the curly braces while the life of Global Variable is till the program termination as it is declared only once in the program. • Register Variable :- Register variables are used to execute the program faster. • The syntax to declare Register variable is:- register data_type variable_name;