In the previous tutorial we talked about functions, What are they, How to declare them etc. Now in this article we’ll be looking at In this tutorial we’ll be looking at a basic sample program, how it works and some basic rules/tips to keep in mind. Simple Program using Functions Function.c Code: #include<stdio.h> void function1() { printf("Hello i am a Void Function! :D\n"); } int function2( int input ) { printf("Hello I am a input/output function , I take int and input and give int as output\n"); printf("Input Recieved : %d\n",input); return ( input + 1); } int main() { int output = 0; printf("Calling Function 1 , Type : Void !\n"); function1(); printf("------------------\n\n"); printf("Calling Function 2 , Type : Int (Output) , Int (Input)!\n"); output = function2(22); printf("Output : %d\n",output); printf("------------------\n"); } Explanation:- In the above program we declared 2 functions, first functions is a void function with no return (output). And the second function is an int type function with int as input and int as output. After that we declare a variable named output , This variable is to store the output received from function 2. We provide 22 as input to function 2 and store the output in the variable named output. The program calls 2 functions separately and Gives us the output :- Code: Calling Function 1 , Type : Void ! Hello i am a Void Function! :D ------------------ Calling Function 2 , Type : Int (Output) , Int (Input)! Hello I am a input/output function , I take int and input and give int as output Input Recieved : 22 Output : 23 ------------------ Return Statement (In functions):- The return statement specifies the output to be returned to the caller , Eg : In our case we are calling the function from the main() function so main() is the caller. Some Tips/Facts Regarding Functions A function can be called multiple number of times. The Variable declared or initialized in a function will not be applicable for other functions unless the variable is globally declared. Any function can be called from any other function. The Function can also call itself , These type of functions are called recursive functions After each function has done its job the control returns to main thereafter if the main has done its job the program execution stops. If a function is not called it does not execute.
good one sir i want tracing for towers for hanoi program(recursive function) Also how recursive programs would be traced by the compiler