346 Programming and Data Structures
pointer 'q' contains the base address of u [ ]. Hence, pointers p and q are global pointers. They can
be accessed through any function.
10.10 RECURSION
The C language supports recursive feature, that is, a function is called repeatedly by itself. Recursion
can be used directly or indirectly. The direct recursion function calls to itself till the condition is
true. In indirect recursion a function calls to another function, then the called function calls to the
calling function.
10.31 Write a program to call the mainO function recursively and perform a sum of 1 to 5
numbers.
# include <8tdio.&>
# include <procaa*«h>
in t x # s;
void m a in (in t);
void main(x)
s=s+x;
p rin tf ( mn x ® %d s - % d~,x,e);
i f (x*®5)
e x i t (0 );
tnaitt(++x);
>
OUTPUT:
x = 1 s = 1
x = 2 s = 3
x = 3 s = 6
x = 4 s= 10
x = 5 s= 15
Explanation In the above program variables x and y are declared outside main () function.
Initially their values are zero. Followed by it the prototype of function main () is defined. The
variable x is passed through the main () function. The variable x is added to variable s till value of
x reaches 5. Every time function main () is called repeatedly, x is incremented. The result of the
program is displayed at the output. The value of x in main () is 1 because it is a command line
argument.