The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
" What you have to do when I call you"
yes, the above quotes clearly define the purpose of user defined function. By speaking conceptually, a programmer can define their own sets of code inside a function and use it for n number of times using its function name.
The user-defined functions are classified into four types, according to parameters and return value.
The calling function will not send parameters to the called function and called function will not pass the return value to the calling function.
#include <stdio.h> void add(); //function declaration int main() { //main function definition add(); //function call without passing arguments } //function definition void add() { int a = 5, b = 10; int c; printf(" The values of a and b : %d %d ", a, b); c = a + b; printf(" \nsum : %d ", c); //no return values to the calling function }
The program illustrates that, there are no parameters passed through the calling function and no return value to the calling function main().
The calling function will pass parameters to the called function but called function will not pass the return value to the calling function.
#include <stdio.h> void add(int,int); //function declaration int main() { //main function definition int sum; int a = 5, b = 10; printf(" The values of a and b : %d %d ", a, b); add( a, b); //function call with passing arguments to called function } // function definition void add(int a, int b) { int c; c = a + b; printf(" \nsum : %d ", c); //no return values to the calling function main }
The program illustrates that, parameters are passed to the called function(add) from calling function(main) but no return values are passed from called function(add) to the calling function (main).
The calling function will not pass parameters to the called function but called function will pass the return value to the calling function.
#include <stdio.h> int add(); //function declaration int main() { //main function definition int sum; sum = add(); //function call without passing arguments to called function printf(" \nsum = %d ", sum); } // function definition int add() { int c; int a = 5, b = 10; printf(" The values of a and b : %d %d ", a, b); c = a + b; return c; //passing return values to the calling function main }
The program illustrates that, no parameters are passed to the called function(add) from calling function(main) but return value is passed from called function(add) to the calling function (main). The return values is assigned to the variable sum.
The calling function will pass parameters to the called function and called function also pass the return value to the calling function.
#include <stdio.h> int add(int, int); //function declaration int main() { //main function definition int sum; int a = 5, b = 10; printf(" The values of a and b : %d %d ", a, b); sum = add( a, b); //function call with passing arguments printf(" \nsum = %d ", sum); } // function definition int add(int a, int b) { int c; c = a + b; return c; //passing return values to the calling function main }
The program illustrates that, parameters are passed to the called function (add) from calling function (main) and return value is passed from called function (add) to the calling function (main). The return values is assigned to the variable sum.
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019