Monday, July 02, 2007

returning array pointer

This programs shows to return a function pointer: -

----------------------------------------------------------------------------------------------------------

#include <stdio.h>

#define NINE 9

void func(int a[], int size);
int *func2(void);

int main(void)
{
int a[] = {3,2,4};
int *(*j)(void) = func2;

func(a, sizeof a / sizeof *a);
printf("\nTraversing second list\n");
func(j(), NINE);
return 0;
}

void func(int a[], int size)
{
int i;

for (i = 0; size > i; i++) {
printf("%d\n", a[i]);
}
}

int *func2(void)
{
static int b[NINE] = {112,3,4,5,6,7,9,4,10};

return b;
}

----------------------------------------------------------------------------------------------------------

Courtesy: -
http://groups.google.com/group/comp.lang.c/browse_thread/thread/7d03fbafd8f5c6c9/#

--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India

No comments: