SlideShare a Scribd company logo
c-Functions power point presentation on c functions
Introduction
What is function?
How functions will work?
How to declare a function in C language?
What are the different types of functions are
there in C language?
Example programs.
Introduction
Modular Programming
Modular Programming
Break a large problem into smaller pieces
Smaller pieces sometimes called ‘modules’ or
‘subroutines’ or ‘procedures’ or functions
Divide and Conquer
Divide and Conquer
Why Modular Programming?
Why Modular Programming?
Helps in managing the complexity of the
program
- Smaller blocks of code - Easier to read
Encourages re-use of code
Within a particular program or across different programs
Allows independent development of code
Provides a layer of ‘abstraction’
What is function?
Function is a set of instructions to carry out a particular task.
The Function after processing returns a single value.
In other word, we say a Function is a group of statements
that can perform any particular task.
Function in programming is a segment that groups a number
of program statements to perform specific task
Every C program has at least one function, which is main().
We have already used functions like…..
Every function in C must have two things…
A function declaration tells the compiler about a function's
name, return type, and parameters.
A function definition provides the actual body of the
function.
A function declaration tells the compiler about a function's
name, return type, and parameters.
A function declaration must be done within main function or
before main function.
A function definition must be done before main function or
after main function.
A function definition provides the actual body of the
function.
Types of functions?
Predefined
Userdefined
Predefined functions
Actually all predefined functions in C Language are defined
inside in any one of the header files.
If the functionality of a function is defined by the compiler
those functions are called predefined functions.
The functionality of the predefined function is fixed, users
cannot change or redefine it.
Predefined functions
Predefined functions are also called as System Defined
functions or Library functions.
NOTE
User-defined functions
User-defined functions are small programs that you can
write to perform an operation.
If the functionality of a function is defined by the user those
functions are called user-defined functions.
Users are free to define their own code for the user-defined
functions. Every user-defined function must have the
following….
Declaring User-defined functions
Syntax
Example
We also call it as Function Prototype
NOTE
Definition of User-defined functions
Syntax
Example
Calling User-defined functions
Syntax
Example
Working of Functions
Example Program
void main()
{
int a, b, c;
void addition(int , int);
printf(“We are in main…..n”);
printf(“Enter any two numbers: ”);
scanf(“%d%d”, &a, &b);
addition(a, b);
printf(“We are again in main…..”);
}
void addition(int x, int y)
{
printf(“SUM = %dn”, x+y);
}
Important terms in functions
It is nothing but a function declaration
It is used to initiate the function execution. That means this
line decides when a function has to be perform its task.
It is nothing but the function definition. It decides what is to
be done by the function on a function call.
Example Program
void main()
{
int a, b, c;
void addition(int , int);
printf(“We are in main…..n”);
printf(“Enter any two numbers: ”);
scanf(“%d%d”, &a, &b);
addition(a, b);
printf(“We are again in main…..”);
}
void addition(int x, int y)
{
printf(“SUM = %dn”, x+y);
}
Prototype
Calling
Called
Parameters & Return Value
Parameters are the data values which are passed from
calling function to called function
Return value is the data value which passed from called
function to calling function
For a function we can have any number of parameters
For a function we can have only one return value
In a function the total number of parameters and the order
of the parameters must be same in all function prototype,
function calling and function definition
Parameters & Return Value
To return a value from called function to calling function we
use ‘return’ statement
Parameter types
In C programming language there are two types of
parameters
These are the parameters used at the time of function
calling
Whenever we pass actual parameters copy of its value is
sent to the called function but not entire variable
These are the parameters used at called function as
receivers of the actual parameters
The order of the actual parameters and their datatypes
should exactly match with the order and datatypes of the
formal parameters
Function types
Based on the parameters and return value, functions are
classified into FOUR types
In this type, there is no data transfer between calling and
called functions
Simple control transfer from calling function to called
function, executes called function body and comes back to
the calling function.
Everything is performed within the called function like
reading data, processing data and displaying result.
This type of functions are used to print some message,
line….
void main()
{
void add();
printf(“We are in main….n”);
add();
printf(“We are again in main….n”);
}
void add()
{
int a,b,c;
printf(Enter any two numbers: );
scanf(“%d%d”, &a, &b);
c = a + b;
printf(“Result = %d”, c);
}
void main( )
{
void add( );
printf(“We are in main….n”);
add( );
printf(“We are again in main….n”);
}
void add( )
{
int a,b,c;
printf(Enter any two numbers: );
scanf(“%d%d”, &a, &b);
c = a + b;
printf(“Result = %d”, c);
}
Control
No input
Control
No return value
In this type, there is data transfer from calling to called
function, but not from called to calling function.
Simple control transfer from calling function to called
function along with some data (parameters), executes called
function body and comes back to the calling function
without any data.
This type of functions are depend on the calling function.
Generated result is utilized by called function and nothing
will be sent back to the calling function.
void main()
{
void add( int, int );
printf(“We are in main….n”);
add( 10, 20);
printf(“We are again in main….n”);
}
void add(int a, int b)
{
int c;
c = a + b;
printf(“Result = %d”, c);
}
void main( )
{
void add( int, int );
printf(“We are in main….n”);
add( 10, 20 );
printf(“We are again in main….n”);
}
void add( int a, int b)
{
int c;
c = a + b;
printf(“Result = %d”, c);
}
Control
10 & 20 as input
Control
No return value
In this type, there is no data transfer from calling to called
function, but from called to calling function one data is sent.
Simple control transfer from calling function to called
function, executes called function body and a data value is
sent back to the calling function from called function.
This type of functions are called function is independent. It
reads data, process data and result is sent back to the calling
function.
void main()
{
int c;
int add( );
printf(“We are in main….n”);
c = add( );
printf(“Result = %dn”, c);
}
int add( )
{
int a, b;
printf(“Enter any two numbers:”);
scanf(“%d%d”, &a, &b);
return (a + b);
}
void main( )
{
int c;
int add( );
printf(“We are in main….n”);
c = add( );
printf(“Result = %dn”, c);
}
void add( )
{
int a,b;
printf(Enter any two numbers: );
scanf(“%d%d”, &a, &b);
return (a + b);
}
Control
No input
Control
30 as return value
input values for a & b are 10 & 20 respectively
In this type, there is data transfer from calling to called
function, and from called to calling function one data is sent
back.
Control transfer from calling function to called function
along with data, executes called function body and a data
value is sent back to the calling function from called
function.
In this type of functions are called & calling functions both
dependent on each other.
void main()
{
int c;
int add( int, int );
printf(“We are in main….n”);
c = add( 10, 20 );
printf(“Result = %dn”, c);
}
int add( int a, int b)
{
return (a + b);
}
void main( )
{
int c;
int add( int, int );
printf(“We are in main….n”);
c = add( 10, 20 );
printf(“Result = %dn”, c);
}
void add( int a, int b)
{
return (a + b);
}
Control
10 & 20 as input
Control
30 as return value
Different ways to make a function call
There are THREE ways of making function call…
1.
1. From main function
From main function
We have already seen making a function call from main
function.
When we make a function call from main, the control
transfers to called function, executes it, again comes back to
the main function.
2. From another user-defined function
2. From another user-defined function
We can also make a function call from another user-defined
function.
void main()
{
function1();
}
void function1()
{
function2();
}
void function2()
{
body of the function;
}
3. From same function
3. From same function
We can also make a function call from same function. That
means function calls itself
If a function calls itself, then it is called as “RECURSION”.
When a function calls itself until the last call is invoked till
that time the first call also remains open.
At every time, a function invoked, the function returns the
result of previous call.
void main( )
{
printf(“This is example of Recursion!!!”);
main( );
}
This is example of Recursion!!!
This is example of Recursion!!!
This is example of Recursion!!!
This is example of Recursion!!!
…….
int factorial( int );
void main( )
{
int fact, n;
printf(“Enter any positive integer: ”);
scanf(“%d”, &n);
fact = factorial( n );
printf(“Factorial of %d is %d”, n, fact);
}
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
return temp;
}
int factorial( int );
void main( )
{
int fact, n;
printf(“Enter any positive integer:
”);
scanf(“%d”, &n);
fact = factorial( n );
printf(“Factorial of %d is %d”, n,
fact);
}
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
return temp;
}
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
return temp;
}
n = 3 n
3
temp
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
return temp;
}
3 * factorial(2)
n = 2
n
2
temp
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
return temp;
}
2 * factorial(1)
n = 1
int factorial( int n )
{
int temp;
if( n == o)
return 1;
else
temp = n * factorial( n-1 );
1 * factorial(0)
n
1
0
n
temp
temp
n = 0
1
1
1
1*1 = 1
2
2*1 = 2
2
3*2 = 6
6
6
Memory Allocation
Ad

More Related Content

Similar to c-Functions power point presentation on c functions (20)

Function
Function Function
Function
Kathmandu University
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
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
 
C function
C functionC function
C function
thirumalaikumar3
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
TeshaleSiyum
 
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
FunctionsFunctions
Functions
Pragnavi Erva
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
Dr. Chandrakant Divate
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
Functions in c
Functions in cFunctions in c
Functions in c
kalavathisugan
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 

More from 10300PEDDIKISHOR (7)

c-step-by-step-execution power point presentation
c-step-by-step-execution power point presentationc-step-by-step-execution power point presentation
c-step-by-step-execution power point presentation
10300PEDDIKISHOR
 
Structures-in-C programming with examples
Structures-in-C programming with examplesStructures-in-C programming with examples
Structures-in-C programming with examples
10300PEDDIKISHOR
 
file handling in c programming with file functions
file handling in c programming with file functionsfile handling in c programming with file functions
file handling in c programming with file functions
10300PEDDIKISHOR
 
Unity JDBC ICEIS ppt UnityJDBC ICEIS ppt
Unity JDBC ICEIS ppt UnityJDBC ICEIS pptUnity JDBC ICEIS ppt UnityJDBC ICEIS ppt
Unity JDBC ICEIS ppt UnityJDBC ICEIS ppt
10300PEDDIKISHOR
 
JDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each DriverJDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
Java Database Connectivity Java Database
Java Database Connectivity Java DatabaseJava Database Connectivity Java Database
Java Database Connectivity Java Database
10300PEDDIKISHOR
 
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
10300PEDDIKISHOR
 
c-step-by-step-execution power point presentation
c-step-by-step-execution power point presentationc-step-by-step-execution power point presentation
c-step-by-step-execution power point presentation
10300PEDDIKISHOR
 
Structures-in-C programming with examples
Structures-in-C programming with examplesStructures-in-C programming with examples
Structures-in-C programming with examples
10300PEDDIKISHOR
 
file handling in c programming with file functions
file handling in c programming with file functionsfile handling in c programming with file functions
file handling in c programming with file functions
10300PEDDIKISHOR
 
Unity JDBC ICEIS ppt UnityJDBC ICEIS ppt
Unity JDBC ICEIS ppt UnityJDBC ICEIS pptUnity JDBC ICEIS ppt UnityJDBC ICEIS ppt
Unity JDBC ICEIS ppt UnityJDBC ICEIS ppt
10300PEDDIKISHOR
 
JDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each DriverJDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
Java Database Connectivity Java Database
Java Database Connectivity Java DatabaseJava Database Connectivity Java Database
Java Database Connectivity Java Database
10300PEDDIKISHOR
 
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
Every SQL Query must have: • SELECT clause: specifies columns to be retained ...
10300PEDDIKISHOR
 
Ad

Recently uploaded (20)

seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Ad

c-Functions power point presentation on c functions

  • 2. Introduction What is function? How functions will work? How to declare a function in C language? What are the different types of functions are there in C language? Example programs.
  • 4. Modular Programming Modular Programming Break a large problem into smaller pieces Smaller pieces sometimes called ‘modules’ or ‘subroutines’ or ‘procedures’ or functions Divide and Conquer Divide and Conquer
  • 5. Why Modular Programming? Why Modular Programming? Helps in managing the complexity of the program - Smaller blocks of code - Easier to read Encourages re-use of code Within a particular program or across different programs Allows independent development of code Provides a layer of ‘abstraction’
  • 6. What is function? Function is a set of instructions to carry out a particular task. The Function after processing returns a single value. In other word, we say a Function is a group of statements that can perform any particular task. Function in programming is a segment that groups a number of program statements to perform specific task
  • 7. Every C program has at least one function, which is main(). We have already used functions like…..
  • 8. Every function in C must have two things… A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
  • 9. A function declaration tells the compiler about a function's name, return type, and parameters. A function declaration must be done within main function or before main function.
  • 10. A function definition must be done before main function or after main function. A function definition provides the actual body of the function.
  • 12. Predefined functions Actually all predefined functions in C Language are defined inside in any one of the header files. If the functionality of a function is defined by the compiler those functions are called predefined functions. The functionality of the predefined function is fixed, users cannot change or redefine it.
  • 13. Predefined functions Predefined functions are also called as System Defined functions or Library functions. NOTE
  • 14. User-defined functions User-defined functions are small programs that you can write to perform an operation. If the functionality of a function is defined by the user those functions are called user-defined functions. Users are free to define their own code for the user-defined functions. Every user-defined function must have the following….
  • 15. Declaring User-defined functions Syntax Example We also call it as Function Prototype NOTE
  • 16. Definition of User-defined functions Syntax Example
  • 19. Example Program void main() { int a, b, c; void addition(int , int); printf(“We are in main…..n”); printf(“Enter any two numbers: ”); scanf(“%d%d”, &a, &b); addition(a, b); printf(“We are again in main…..”); } void addition(int x, int y) { printf(“SUM = %dn”, x+y); }
  • 20. Important terms in functions It is nothing but a function declaration It is used to initiate the function execution. That means this line decides when a function has to be perform its task. It is nothing but the function definition. It decides what is to be done by the function on a function call.
  • 21. Example Program void main() { int a, b, c; void addition(int , int); printf(“We are in main…..n”); printf(“Enter any two numbers: ”); scanf(“%d%d”, &a, &b); addition(a, b); printf(“We are again in main…..”); } void addition(int x, int y) { printf(“SUM = %dn”, x+y); } Prototype Calling Called
  • 22. Parameters & Return Value Parameters are the data values which are passed from calling function to called function Return value is the data value which passed from called function to calling function For a function we can have any number of parameters For a function we can have only one return value In a function the total number of parameters and the order of the parameters must be same in all function prototype, function calling and function definition
  • 23. Parameters & Return Value To return a value from called function to calling function we use ‘return’ statement
  • 24. Parameter types In C programming language there are two types of parameters
  • 25. These are the parameters used at the time of function calling Whenever we pass actual parameters copy of its value is sent to the called function but not entire variable
  • 26. These are the parameters used at called function as receivers of the actual parameters The order of the actual parameters and their datatypes should exactly match with the order and datatypes of the formal parameters
  • 27. Function types Based on the parameters and return value, functions are classified into FOUR types
  • 28. In this type, there is no data transfer between calling and called functions Simple control transfer from calling function to called function, executes called function body and comes back to the calling function. Everything is performed within the called function like reading data, processing data and displaying result. This type of functions are used to print some message, line….
  • 29. void main() { void add(); printf(“We are in main….n”); add(); printf(“We are again in main….n”); } void add() { int a,b,c; printf(Enter any two numbers: ); scanf(“%d%d”, &a, &b); c = a + b; printf(“Result = %d”, c); }
  • 30. void main( ) { void add( ); printf(“We are in main….n”); add( ); printf(“We are again in main….n”); } void add( ) { int a,b,c; printf(Enter any two numbers: ); scanf(“%d%d”, &a, &b); c = a + b; printf(“Result = %d”, c); } Control No input Control No return value
  • 31. In this type, there is data transfer from calling to called function, but not from called to calling function. Simple control transfer from calling function to called function along with some data (parameters), executes called function body and comes back to the calling function without any data. This type of functions are depend on the calling function. Generated result is utilized by called function and nothing will be sent back to the calling function.
  • 32. void main() { void add( int, int ); printf(“We are in main….n”); add( 10, 20); printf(“We are again in main….n”); } void add(int a, int b) { int c; c = a + b; printf(“Result = %d”, c); }
  • 33. void main( ) { void add( int, int ); printf(“We are in main….n”); add( 10, 20 ); printf(“We are again in main….n”); } void add( int a, int b) { int c; c = a + b; printf(“Result = %d”, c); } Control 10 & 20 as input Control No return value
  • 34. In this type, there is no data transfer from calling to called function, but from called to calling function one data is sent. Simple control transfer from calling function to called function, executes called function body and a data value is sent back to the calling function from called function. This type of functions are called function is independent. It reads data, process data and result is sent back to the calling function.
  • 35. void main() { int c; int add( ); printf(“We are in main….n”); c = add( ); printf(“Result = %dn”, c); } int add( ) { int a, b; printf(“Enter any two numbers:”); scanf(“%d%d”, &a, &b); return (a + b); }
  • 36. void main( ) { int c; int add( ); printf(“We are in main….n”); c = add( ); printf(“Result = %dn”, c); } void add( ) { int a,b; printf(Enter any two numbers: ); scanf(“%d%d”, &a, &b); return (a + b); } Control No input Control 30 as return value input values for a & b are 10 & 20 respectively
  • 37. In this type, there is data transfer from calling to called function, and from called to calling function one data is sent back. Control transfer from calling function to called function along with data, executes called function body and a data value is sent back to the calling function from called function. In this type of functions are called & calling functions both dependent on each other.
  • 38. void main() { int c; int add( int, int ); printf(“We are in main….n”); c = add( 10, 20 ); printf(“Result = %dn”, c); } int add( int a, int b) { return (a + b); }
  • 39. void main( ) { int c; int add( int, int ); printf(“We are in main….n”); c = add( 10, 20 ); printf(“Result = %dn”, c); } void add( int a, int b) { return (a + b); } Control 10 & 20 as input Control 30 as return value
  • 40. Different ways to make a function call There are THREE ways of making function call…
  • 41. 1. 1. From main function From main function We have already seen making a function call from main function. When we make a function call from main, the control transfers to called function, executes it, again comes back to the main function.
  • 42. 2. From another user-defined function 2. From another user-defined function We can also make a function call from another user-defined function.
  • 44. 3. From same function 3. From same function We can also make a function call from same function. That means function calls itself If a function calls itself, then it is called as “RECURSION”. When a function calls itself until the last call is invoked till that time the first call also remains open. At every time, a function invoked, the function returns the result of previous call.
  • 45. void main( ) { printf(“This is example of Recursion!!!”); main( ); } This is example of Recursion!!! This is example of Recursion!!! This is example of Recursion!!! This is example of Recursion!!! …….
  • 46. int factorial( int ); void main( ) { int fact, n; printf(“Enter any positive integer: ”); scanf(“%d”, &n); fact = factorial( n ); printf(“Factorial of %d is %d”, n, fact); } int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); return temp; }
  • 47. int factorial( int ); void main( ) { int fact, n; printf(“Enter any positive integer: ”); scanf(“%d”, &n); fact = factorial( n ); printf(“Factorial of %d is %d”, n, fact); } int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); return temp; }
  • 48. int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); return temp; } n = 3 n 3 temp int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); return temp; } 3 * factorial(2) n = 2 n 2 temp int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); return temp; } 2 * factorial(1) n = 1 int factorial( int n ) { int temp; if( n == o) return 1; else temp = n * factorial( n-1 ); 1 * factorial(0) n 1 0 n temp temp n = 0 1 1 1 1*1 = 1 2 2*1 = 2 2 3*2 = 6 6 6 Memory Allocation
  翻译: