Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
FUNCTIONS
Shanu k k
shanukk89@gmail.com
www.facebook.com/shanunn
i
twitter.com/shanu
in.linkedin.com/in/shanu
9656153432
• one of the strengths of c language is c
functions,they are easy to define and use
• C function can be classified in to t...
Need for user defined function
• Main is specially recoganized function in
c,every program must have a main function to
in...
• Program is divided in to functional part
,which is independently coded and later
combined in to a single unit
• This ind...
Main program
Function
A
Function
B
Function
c
B1 b2
Definition of function
• function name
• Function type
• List of parameters
• Local variable declaration
• Function statem...
Function_type function _name(parameter list)
{
local variable declaration;
executable statement1;
executable statement2;
…...
Function header
• Type specifies type of value that expected to
return eg:int,float
• Void:function not return anything
• ...
Formal parameter list
• Input data to the function and carry out the
specified task
• Also used to send values to the call...
Function body
• Float mul ( float flt_ x ,float flt_ y)
{
float result; /*local variable*/
result=flt_x*flt_y; /*compute t...
• void display (void)
{
printf(“no type,no parameter”) ;
}
• Void sum( int int_ a,int int_b)
{
printf (“sum is %d,a+b);
Return values and their type
• Return;
or
return(expression);
Main()
{
int y;
Y=mul(10,5) /call/
}
int mul (int x,int y)
{
int p;
p=x*y;
return(p);
}
Function declaration
• Function name
• Function type
• Parameter list
• Terminating semicolon
int add (int x,int y);
• Declaration placed two places in program
1. Above all the function including main
2. Inside a function definition
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, N...
Functions and return type
Upcoming SlideShare
Loading in …5
×

Functions and return type

255 views

Published on

Functions and return type

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Functions and return type

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. FUNCTIONS Shanu k k shanukk89@gmail.com www.facebook.com/shanunn i twitter.com/shanu in.linkedin.com/in/shanu 9656153432
  3. 3. • one of the strengths of c language is c functions,they are easy to define and use • C function can be classified in to two catagories • 1 library function :printf and scanf • 2 user defind function: main
  4. 4. Need for user defined function • Main is specially recoganized function in c,every program must have a main function to indicate where the program has to be execution • If a program condain only main function number of problem,testing and maintaining become difficult
  5. 5. • Program is divided in to functional part ,which is independently coded and later combined in to a single unit • This independently coded programs are called sub programs are referred as function
  6. 6. Main program Function A Function B Function c B1 b2
  7. 7. Definition of function • function name • Function type • List of parameters • Local variable declaration • Function statement • Return statement
  8. 8. Function_type function _name(parameter list) { local variable declaration; executable statement1; executable statement2; ………………………………….. return statement; }
  9. 9. Function header • Type specifies type of value that expected to return eg:int,float • Void:function not return anything • name is valid c identifier • Same rule for other variable name in c
  10. 10. Formal parameter list • Input data to the function and carry out the specified task • Also used to send values to the calling programs • also known as arguments
  11. 11. Function body • Float mul ( float flt_ x ,float flt_ y) { float result; /*local variable*/ result=flt_x*flt_y; /*compute the mul*/ return (result); }
  12. 12. • void display (void) { printf(“no type,no parameter”) ; } • Void sum( int int_ a,int int_b) { printf (“sum is %d,a+b);
  13. 13. Return values and their type • Return; or return(expression);
  14. 14. Main() { int y; Y=mul(10,5) /call/ } int mul (int x,int y) { int p; p=x*y; return(p); }
  15. 15. Function declaration • Function name • Function type • Parameter list • Terminating semicolon int add (int x,int y);
  16. 16. • Declaration placed two places in program 1. Above all the function including main 2. Inside a function definition
  17. 17. Contact Us 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 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com

×