Page 11 - Sample_test_Float
P. 11
Functions and Pointers 11
something equivalent to the following will happen within the compiler implicitly(i.e. the statements will not be
visible but will happen within the compiler )
int *a;// an array variable will be considered as pointer
a = &a[0];// the base address of an array will be stored in the variable a.
Then value of a =&a[0](address of first array variable).
Let us see how the elements of the array are accessed using pointer. As we know the array variable ‘a’ is also
considered as pointer and it will hold the variable a[0].
If we increment the array variable a, then it will move to the next element.
a=>contains the address of the first element.
*a=>contains the value of the first element.
It means a[0] = 10.
a+1=> contains the address of the second element
*(a+1) =>contains the value of the second element.
It means a[0]+1 = a[1] = 20.
a+2=> contains the address of the third element
*(a+2) =>contains the value of the third element
It means a[0]+2 = a[2] = 30.
a+3=> contains the address of the fourth element
*(a+3) =>contains the value of the fourth element
It means a[0]+3 = a[3] = 40.
a+4=> contains the address of the fifth element.
*(a+4) =>contains the value of the fifth element
It means a[0]+4 = a[4] = 50.
Using dereferencing pointer, we can access the value of elements as follows.
*a or a[0] 10
*(a+1) or a[1] 20
*(a+2) or a[2] 30
*(a+3) or a[3] 40
*(a+4) or a[4] 50
5.2.9. Pointer to Functions (Function Pointer)
• A pointer which keeps address of a function is known as Function Pointer.
• No function can return more than one value. But using pointers we can return more than one value.
Consider the example below;let us try to return two values at a time.
void main()
{
int a=10,b=5;
a,b=square(a,b);//this is meaningless and not supported by c
printf(“%d %d”,a,b);
}

