GeekInterview.com
  I am new, Sign me up!
 
Home C
 

What is the default return value of a function?

 
Category: C
Comments (3)


The default return value from a function is int. In other words, unless explicitly specified the default return value by compiler would be integer value from function.  


When a programmer wants other than integer values to be returned from function then it is essential that the programmer follows the steps provided here below:


1. Mention the return type in the calling function 
2. Mention the return type in the called function.


Both steps 1 and 2 must be made if the return value is other than integer.


Let us see how to do this with a example:


main()
{
float x=2.5,y=3.5,z;
float sample();
z=sample(x,y);
printf(“%f”,z);
}


float sample(x1,y1,z1)
float x1,y1,z1;
{
float z1;
z1= x1+ y1
return(z1);
}


Here the output would be


    6.0


Here the return value is float from function sample. Therefore as said before it is declared in calling function namely main() as


    float sample()


after the variable declaration in main() and it is also declared in the function sample as


    float sample(x1,y1,z1)


It is vital for programmers to follow the above method to get correct return value from function.



Read Next: How to call C header that is not provided generally by system in C++?



 

 

Comments


mouin said:

  the default return value of a function in C is integer. If we simply write return at end of the function it return some garbage values.
September 20, 2008, 2:53 am

maha zoromba said:

  How can I receive value or (return value) from the function (ex: return 1 to know that the response of the function)
May 9, 2009, 7:43 pm

rajesh bansal said:

  return_type function_name(arg_type arg_var ,............)
{
//body of function with a return value of specified data type as return_type
}


ex.


int return_flag ()
{
return 1;
}
July 8, 2009, 2:43 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape