Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!agate!stanford.edu!unix!ace!ric From: ric@ace.sri.com (Richard Steinberger) Newsgroups: comp.lang.c Subject: Simple ptr passing question Message-ID: <24268@unix.SRI.COM> Date: 13 May 91 23:56:05 GMT Sender: news@unix.SRI.COM Reply-To: ric@ace.sri.com (Richard Steinberger) Organization: SRI International Lines: 37 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 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 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@ace.sri.com