Passing arguments to Function in C programming and using Return keyword to return value. Functions are used to divide a large program into sub-programs for easy control.
#include<stdio.h>
#include<conio.h>
int fun(int, int); //defining Integer function with parameters.
int fun(int a, int b) //this is function which Return type is Integer,
{ //and passing here arguments to parameter.
int c = a + b; //adding 'a' and 'b' value and assigning to 'c'.
return c; //returning 'c' value, U also write like 'return (c);'.
}
void main()
{ //calling Function and passing arguments to parameters and
printf("%d", fun(6, 5)); //printing Return value.
getch();
}
#include<stdio.h>
#include<conio.h>
int fun(int); //defining function with parameter which Return
void main() //type is Integer.
{
int a, b;
a = 5;
b = fun(a); //calling and passing argument to parameter and
//assigning Return value to 'b'.
printf("The Returned value is: %d", b); //and printing 'b' value.
getch();
}
int fun(int z) //passing argument here to parameter 'z'.
{
int x = z + 5; //adding 5 to 'z' value and assigning to 'x'.
return x; //Returning 'x' value, U also write like 'return(x);'.
}
#include<stdio.h>
#include<conio.h>
int fun(int); //defining function with parameter which Return
void main() //type is Integer.
{
int a = 5; //calling and passing argument to parameter and printing
printf("The Returned value is: %d", fun(a)); //Returned value.
getch();
}
int fun(int z) //passing argument here to parameter 'z'.
{
int x = z + 5; //adding 5 to 'z' value and assigning to 'x'.
return x; //Returning 'x' value, U also write like 'return(x);'.
}