SlideShare a Scribd company logo
PREPARED BY: -
D E V I N B A B A R I Y A ( 3 3 )
U T K A R S H D U B E Y ( 3 4 )
K R U S H A L K A K A D I Y A ( 3 5 )
M E E T S O N I ( 3 7 )
P R I Y A M B H A T T ( 3 8 )
M I L A N S U T H A R ( 3 9 )
Subject: FUNCTION
INTRODUCTION
Every ‘C’ program is collection of functions. In every
‘C’ program, main() function must be there, because
the execution of program starts from main()
function.
Function is a group of statements as a single unit
known by some name which is performing some well
defined task.
The functions which are created by programmer in a
program are called as a user-defined functions.
The functions which are readily available in library
are called as library functions.
Advantages of Functions
 It facilitates top-down modular programming,
whereby the large problem is divided into small parts
and each small part is handled later in depth.
 Function can be used in other program also, so labor
is reduced.
 It reduced the size of code, if that code is repetitively
used in program.
 It allows term-work for large project, individual
members of term has to concentrate on function
given to them and not on whole complex problem.
FUNCTION CPU
User defined functions
 User defined functions are created for doing some
specific task in a program. The code is written as one
unit having a name.
 As the size of program increases, It becomes difficult
to understand.
 The code of function is written only once in the
program and called for any number of times from the
program whenever required.
Built-in functions
 These are the functions which are readily available
and placed in side the library.
 Their prototypes are declared in various header files
depending on the category to which they belong to.
 We need to understand the prototype of built-in
function and include that header file in our program.
Function declaration
 The syntax for declaring function is:
type function_name(argument(s));
Here, type specifies the type of value returned,
function_name specifies name of user defined
function, and in bracket argument(s) specifies the
arguments supplied to the function as comma
separated list of variables.
The declaration of a function is terminated by
semicolon (;) symbol. The declaration is also called
as prototype of a function.
Function Definition
 The syntax for definition of function is:
type function_name(argument(s));
{
statement(s);
}
Here, type, function_name and argument(s) have same meaning as
before. The statement(s) within { } symbols indicate the body of a
function. Here, the actual logic of the work of function is implemented.
If the return type is not mentioned, then by default it is taken as int. We
can not define function inside a function. We can call one function from
other. If the function return type is other than void, there must be return
statement in the function. The returned value can be put in brackets but it
is not compulsory.
Category of functions
 The function in ‘C’ language can be divided in following categories:
1) Functions with no arguments and no return value
2) Functions with arguments and no return value
3) Functions with arguments and with return value
When we have function which takes arguments, in that case we need to
understand the formal parameters and actual parameters.
The variables or parameters used in definition of function are called as
formal parameters. while, parameters used in the call to the functions are
called as actual parameters.
Scope of variables
 By scope of variables, we mean in what part of the
program the variable is accessible. There are two
types of scope.
1.) local and 2.) Global
Difference between local and global variables :
Local variables Global variables
Declared inside function body Declared outside body
Not initialized automatically Initialized automatic by value 0
Use of local variables advisable Too much use of global variables
make program difficult to debug, so
use with care
Parameter passing to function
 When a function is called from other function,the
parameters can be passed in two ways.
1) Call by value 2) Call by reference
1) Call by value : In call by value, argument value are
passed to the function , the contents of actual parameters
are copied into the formal parameters. The called function can not
change the values of the variables which are passed.
2) Call by reference : In call by reference, as the name suggests,
the reference of the parameter is passed to the function and not the
value. Call by reference is used whenever we want to change the
value of local variables declared in one function to be changed by
other function
Recursion
 Sometimes, the function is defined in terms of itself.
Recursion is the process by which a function calls itself.
Because the function calls itself , there must be some
condition to stop recursion; otherwise it will lead to infinite
loop.
Types of recursion:
Direct recursion :- In the case of direct recursion, a function explicitly
calls.
Indirect recursion :- The function calls another function, which ultimately
calls the caller function.
Advantages of recursion :
 Easy solution for recursively defined problems.
 Complex programs can be easily written in less code.
Parameters as array and string
As a array
 We can pass the whole array as a parameter to the function.
If we pass the name of an array as an argument, we are
effectively passing whole array as an argument. Naturally,
passing an address of an array is call by reference.
As a string
 It is character array as parameter, because string is stored
in a single dimensional array of character type. We can
write user defined functions to manipulate strings. In this
section , we will understand how a string can be passed as a
parameter to a function.
Storage classes
 The storage class of a variable determines the scope
and lifetime of a variable. There are four storage
classes.
1)Auto
2)Register
3)Static
4)External
Auto
If we do not specify the storage specify with variable,
by default it is auto. All the local variable have auto
storage class. Auto variables are stored in memory,
garbage initial value, scope local to function and
lifetime till the control remains in that function. As the
name suggests, auto variables are created when the
function is called and destroyed automatically when
the function terminates.
Register
Variables which are to be stored in the registers of CPU
are called as register variables. Register keyword is
used for that purpose, for example,
register int a;
declaration the variables as a register variable.
Storage of register variable take place in registers ,
have garbage value, scope local to function and are
created when the function is called and destroyed
automatically when the function terminates.
Static
All the global variables are by default of static storage
class. Default value of static variable is 0. static global
variable is available throughout the entire file in which
it is declared, while static local variable is available in
the function in which it is defined, but is initialized
only once and retains its value even when the control
goes out of the function.
Static variables are stored in memory, default initial
value 0, scope is local to function or file in which
declared and lifetime is entire program execution with
retaining values between function calls.
External
 Normally, the scope of global variable starts from its
definition up to the end of the program. So, the
functions which are defined before the definition of
global variable can not access it.
 Storage in memory, default initial value 0, scope is
global all the files of program and life is entire
program execution.
Thank
you
Ad

More Related Content

What's hot (20)

Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Shakti Singh Rathore
 
Functions in C - Programming
Functions in C - Programming Functions in C - Programming
Functions in C - Programming
GaurangVishnoi
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
Prof. Dr. K. Adisesha
 
Functions in c
Functions in cFunctions in c
Functions in c
reshmy12
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1
sirikeshava
 
4. function
4. function4. function
4. function
Shankar Gangaju
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
primeteacher32
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Functions in C
Functions in CFunctions in C
Functions in C
Shobhit Upadhyay
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Functions
FunctionsFunctions
Functions
Septi Ratnasari
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Harsh Pathak
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
Alisha Korpal
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
Appili Vamsi Krishna
 
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
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
Srajan Mor
 
Built in function
Built in functionBuilt in function
Built in function
MD. Rayhanul Islam Sayket
 

Viewers also liked (13)

Cpu and its functions
Cpu and its functionsCpu and its functions
Cpu and its functions
myrajendra
 
08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)
Akhila Dakshina
 
Parts of CPU
Parts of CPUParts of CPU
Parts of CPU
WilliamBrooks123
 
Parts of cpu
Parts of cpuParts of cpu
Parts of cpu
findclick read
 
Power Point Lesson 02
Power Point Lesson 02Power Point Lesson 02
Power Point Lesson 02
Nasir Jumani
 
Programming language
Programming languageProgramming language
Programming language
Shuja Qais
 
Components of a computer system
Components of a computer systemComponents of a computer system
Components of a computer system
Mark Santos
 
Central processing unit
Central processing unitCentral processing unit
Central processing unit
Kamal Acharya
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
Future of Computers
Future of ComputersFuture of Computers
Future of Computers
guest19ab3c
 
Cpu presentation
Cpu presentationCpu presentation
Cpu presentation
Harry Singh
 
Cpu ppt cse
Cpu ppt cseCpu ppt cse
Cpu ppt cse
Manpreet Kaur Sidhu
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
Ad

Similar to FUNCTION CPU (20)

04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
Notes of Important Programming Fundamental Questions
Notes of Important Programming Fundamental QuestionsNotes of Important Programming Fundamental Questions
Notes of Important Programming Fundamental Questions
Adeel Rasheed
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
Function in C++
Function in C++Function in C++
Function in C++
Prof Ansari
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
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
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
Hattori Sidek
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
bhuvanalakshmik2
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Lecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptxLecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
shivas379526
 
FUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxFUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptx
SafnaSaff1
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
KalashJain27
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
Notes of Important Programming Fundamental Questions
Notes of Important Programming Fundamental QuestionsNotes of Important Programming Fundamental Questions
Notes of Important Programming Fundamental Questions
Adeel Rasheed
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
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
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Lecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptxLecture_5_-_Functions_in_C_Detailed.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
shivas379526
 
FUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxFUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptx
SafnaSaff1
 
Ad

More from Krushal Kakadia (7)

TEST of hypothesis
TEST of hypothesisTEST of hypothesis
TEST of hypothesis
Krushal Kakadia
 
Fmd riveted joints
Fmd riveted jointsFmd riveted joints
Fmd riveted joints
Krushal Kakadia
 
Planimeter
PlanimeterPlanimeter
Planimeter
Krushal Kakadia
 
Levelling
LevellingLevelling
Levelling
Krushal Kakadia
 
Entropy
EntropyEntropy
Entropy
Krushal Kakadia
 
Capacitors
CapacitorsCapacitors
Capacitors
Krushal Kakadia
 
Steam and its properties
Steam and its propertiesSteam and its properties
Steam and its properties
Krushal Kakadia
 

Recently uploaded (20)

RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 

FUNCTION CPU

  • 1. PREPARED BY: - D E V I N B A B A R I Y A ( 3 3 ) U T K A R S H D U B E Y ( 3 4 ) K R U S H A L K A K A D I Y A ( 3 5 ) M E E T S O N I ( 3 7 ) P R I Y A M B H A T T ( 3 8 ) M I L A N S U T H A R ( 3 9 ) Subject: FUNCTION
  • 2. INTRODUCTION Every ‘C’ program is collection of functions. In every ‘C’ program, main() function must be there, because the execution of program starts from main() function. Function is a group of statements as a single unit known by some name which is performing some well defined task. The functions which are created by programmer in a program are called as a user-defined functions. The functions which are readily available in library are called as library functions.
  • 3. Advantages of Functions  It facilitates top-down modular programming, whereby the large problem is divided into small parts and each small part is handled later in depth.  Function can be used in other program also, so labor is reduced.  It reduced the size of code, if that code is repetitively used in program.  It allows term-work for large project, individual members of term has to concentrate on function given to them and not on whole complex problem.
  • 5. User defined functions  User defined functions are created for doing some specific task in a program. The code is written as one unit having a name.  As the size of program increases, It becomes difficult to understand.  The code of function is written only once in the program and called for any number of times from the program whenever required.
  • 6. Built-in functions  These are the functions which are readily available and placed in side the library.  Their prototypes are declared in various header files depending on the category to which they belong to.  We need to understand the prototype of built-in function and include that header file in our program.
  • 7. Function declaration  The syntax for declaring function is: type function_name(argument(s)); Here, type specifies the type of value returned, function_name specifies name of user defined function, and in bracket argument(s) specifies the arguments supplied to the function as comma separated list of variables. The declaration of a function is terminated by semicolon (;) symbol. The declaration is also called as prototype of a function.
  • 8. Function Definition  The syntax for definition of function is: type function_name(argument(s)); { statement(s); } Here, type, function_name and argument(s) have same meaning as before. The statement(s) within { } symbols indicate the body of a function. Here, the actual logic of the work of function is implemented. If the return type is not mentioned, then by default it is taken as int. We can not define function inside a function. We can call one function from other. If the function return type is other than void, there must be return statement in the function. The returned value can be put in brackets but it is not compulsory.
  • 9. Category of functions  The function in ‘C’ language can be divided in following categories: 1) Functions with no arguments and no return value 2) Functions with arguments and no return value 3) Functions with arguments and with return value When we have function which takes arguments, in that case we need to understand the formal parameters and actual parameters. The variables or parameters used in definition of function are called as formal parameters. while, parameters used in the call to the functions are called as actual parameters.
  • 10. Scope of variables  By scope of variables, we mean in what part of the program the variable is accessible. There are two types of scope. 1.) local and 2.) Global Difference between local and global variables : Local variables Global variables Declared inside function body Declared outside body Not initialized automatically Initialized automatic by value 0 Use of local variables advisable Too much use of global variables make program difficult to debug, so use with care
  • 11. Parameter passing to function  When a function is called from other function,the parameters can be passed in two ways. 1) Call by value 2) Call by reference 1) Call by value : In call by value, argument value are passed to the function , the contents of actual parameters are copied into the formal parameters. The called function can not change the values of the variables which are passed. 2) Call by reference : In call by reference, as the name suggests, the reference of the parameter is passed to the function and not the value. Call by reference is used whenever we want to change the value of local variables declared in one function to be changed by other function
  • 12. Recursion  Sometimes, the function is defined in terms of itself. Recursion is the process by which a function calls itself. Because the function calls itself , there must be some condition to stop recursion; otherwise it will lead to infinite loop. Types of recursion: Direct recursion :- In the case of direct recursion, a function explicitly calls. Indirect recursion :- The function calls another function, which ultimately calls the caller function. Advantages of recursion :  Easy solution for recursively defined problems.  Complex programs can be easily written in less code.
  • 13. Parameters as array and string As a array  We can pass the whole array as a parameter to the function. If we pass the name of an array as an argument, we are effectively passing whole array as an argument. Naturally, passing an address of an array is call by reference. As a string  It is character array as parameter, because string is stored in a single dimensional array of character type. We can write user defined functions to manipulate strings. In this section , we will understand how a string can be passed as a parameter to a function.
  • 14. Storage classes  The storage class of a variable determines the scope and lifetime of a variable. There are four storage classes. 1)Auto 2)Register 3)Static 4)External
  • 15. Auto If we do not specify the storage specify with variable, by default it is auto. All the local variable have auto storage class. Auto variables are stored in memory, garbage initial value, scope local to function and lifetime till the control remains in that function. As the name suggests, auto variables are created when the function is called and destroyed automatically when the function terminates.
  • 16. Register Variables which are to be stored in the registers of CPU are called as register variables. Register keyword is used for that purpose, for example, register int a; declaration the variables as a register variable. Storage of register variable take place in registers , have garbage value, scope local to function and are created when the function is called and destroyed automatically when the function terminates.
  • 17. Static All the global variables are by default of static storage class. Default value of static variable is 0. static global variable is available throughout the entire file in which it is declared, while static local variable is available in the function in which it is defined, but is initialized only once and retains its value even when the control goes out of the function. Static variables are stored in memory, default initial value 0, scope is local to function or file in which declared and lifetime is entire program execution with retaining values between function calls.
  • 18. External  Normally, the scope of global variable starts from its definition up to the end of the program. So, the functions which are defined before the definition of global variable can not access it.  Storage in memory, default initial value 0, scope is global all the files of program and life is entire program execution.