Return integer from the function in C by R4R Team

For return the integer value from the function we need to make the return type as a int.

Syntax-

int function_name()
{
return value;
}

Example-
int f()
{
return 1;
}
// no error

void f()
{
return 1;
}
// Give an error


program-

#include< stdio.h>
int function() //definition
{
printf("You make the function\n");
return 1;
}
int main()
{
int a;
printf("Inside main function\n");
a=function(); //calling
printf("%d",a);
return 0;
}


output-

Inside main function
You make the function
1

-In this program, we make a function named as function() have integer return type, this means that it only return the integer value.
-So function() return the value 1 by return 1; and this value is catch by the variable 'a' in main() function.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!