Page 165 - DCAP407_DATA_STRUCTURE
P. 165
Data Structure
int s;
/* The show function is defined globally which does not return any value */
void show (void);
/* main function */
main ()
{
/* If s value is equal to 5, the program execution comes to an end*/
if (s==5) exit (0);
/* show function is called */
show ();
}
/* show function definition */
void show ()
{
/* Print the value of s */
printf (“%d”, s);
/* Increment the value of s */
s++;
/* main function is called */
main ();
}
Output:
0 1 2 3 4
In this example:
1. First the stdio.h header file is included using the include keyword.
2. Then, the conio.h header file that creates text user interfaces are included,
using the include keyword.
3. Then, the process.h header file is included using the include keyword.
4. Then, the integer variable s is declared globally and initialized.
5. Then, show function is defined globally which does not return any value.
6. Execution begins in the main () function.
7. In main(),
(a) First, using an ‘if’ condition, the value of s is checked. If the value is
equal to 5, the program execution comes to an end.
(b) Finally, the show function is invoked.
8. In the show function,
(a) First, the value of s is printed.
(b) Then, the value of s is incremented.
(c) Finally, the main function is invoked.
9.2 Anatomy of Recursive Call
Recursive function comprises two types of cases. They are:
1. A base case
2. A recursive case
A base case is the smallest instance of the problem whose solution is not recursive. It guarantees the
termination of a function. Even a small problem can have many base cases.
158 LOVELY PROFESSIONAL UNIVERSITY