This document provides an overview of functions in C programming. It defines a function as a block of code that performs a specific task and can be called multiple times. The key points covered are:
- Functions allow programs to be divided into smaller, reusable tasks.
- Functions may return data to the calling function and accept arguments to operate on.
- Function prototypes provide the compiler with function signatures before they are defined.
- Function definitions implement the code bodies with the same return type and arguments as the prototype.
- Functions can be called by value, where arguments are copied, or by reference, where addresses are passed.
3. CONTENTS
• What is a function??
• Advantages
• How the function works?
• Function prototypes
• Function defnitions
4. A large program in c can be divided to many subprogram
The subprogram is called as a function
Basically a job of function is to do something
C program contain at least one function which is main().
6. Program can be divided into a smaller, simpler task.
Allowing the code to be called many times
Easier to read and update
Easier Error handling
Code reusability
7. C program doesn't execute the statement in function until the
function is called.
When function is called the program can send the function
information in the form of one or more argument.
When the function is used it is referred to as the called function
Functions often use data that is passed to them from the calling
function
Data is passed from the calling function to a called function by
specifying the variables in a argument list.
Argument list cannot be used to send data. Its only copy
data/value/variable that pass from the calling function.
8. Provides the compiler with the description of functions that will be used
later in the program
Its define the function before it been used/called
Function prototypes need to be written at the beginning of the program.
The function prototype must have :
A return type indicating the variable that the function will be return
Syntax for Function Prototype
• return-type function_name( arg-type name-1,...,arg-type name-n);
Function Prototype Examples
double squared( double number );
void print_report( int report_number );
int get_menu_choice( void);
9. It is the actual function that contains the code that will be execute.
Should be identical to the function prototype.
Syntax of Function Definition
• return-type function_name( arg-1,...,arg-n) ----Function header
{
declarations;
statements;
return(expression);
}
Function Body
10. • Function Definition Examples
float conversion (float celsius)
{
float fahrenheit;
fahrenheit = celcius*33.8
return fahrenheit;
}
• Can be any of C’s data type: int , float etc…
11. Call by value
• In call by value mechanism, the called function
creates a new set of variables in stack and
copies the values of the arguments into them.
12. Call by reference
In call by reference mechanism, instead of
passing values to the function being called,
references/pointers to the original variables
are passed.
14. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
15. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
16. Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us
Editor's Notes
The subprogram posses a self contain components and have well define purpose.