Functions 345
Explanation Interchange of array elements can be done by call by reference. Here, we are passing
the address of array elements of arrays a [] and b [] to the function change (). The function change ()
interchanges the contents of elements.
g )
Global pointer
10.30 Write a program to read array elements declared in different functions using the
global pointer declaration.
# include <stdio.h>
# inclu de <conio.h>
in t *p/*q; vo id m ain()
{
In t aiB 0,call (in t ) ,k[5] ={3,8 ,5,2,5};
p=k;
dxscrO;
call(5);
while (m!=5)
{
printf ("%3d",*q);
m++;
q++;
}
call(int j)
{
static int m=0,u[5]={5,l,6,0,6};
q=u;
while (m!=j)
printf ("%3d",*p);
m++;
p++;
}
printf ("n");
retum(NULL);
}
Q U TPUI;
38525
51606
Explanation In the above program, 'p' and 'q' are declared as global pointers, that is, they are
defined outside the main () function. The pointer 'p' contains the base address of array k [ j and