Return an Array
Since we can return only one value, we return the base address of the array,
so the return type becomes a pointer.
/*
http://www.ProbCOMP.com
The return type specifies the type of value we can return from the function.At a time we can
return only one value.Since we can return only one value, we return the base address of the array,
so the return type becomes a pointer.
*/
#include<stdio.h>
int * add(int *arr)
{
arr[0]=1;
arr[1]=2;
return arr;
}
void main()
{
int array[2];
int *ptr = add(array);
printf("%d , %d",ptr[0],ptr[1]);
}
Download Program


