Simple ptr passing question
Richard Steinberger
ric at ace.sri.com
Tue May 14 09:56:05 AEST 1991
I am a bit rusty with C. Could someone help me with this simple
pointer passing problem. I wanted to pass a ptr to a function and
have the function allocate some space and pass back the address in the ptr.
Here's what I tried:
#include <stdio.h>
main()
{
extern void zip();
int *ip;
zip(ip);
printf("*ip is %d\n",*ip);
}
void zip (iptr)
int *iptr;
{
int * jptr;
jptr = (int *) malloc(sizeof (int) );
*jptr = 12;
iptr = jptr;
}
I know I could have passed back the pointer in a return statement,
I wanted to get this done correctly for now. In the main program,
ip is <nil> on return, instead of pointing to jptr as I had hoped.
Can someone explain what I should have done to get the desired
effect? Thanks in advance for replies and suggestions.
regards,
ric steinberger
ric at ace.sri.com
More information about the Comp.lang.c
mailing list