Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!bacchus.pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.lang.c Subject: Re: SIMPLE malloc & pointer question Message-ID: <1898@tkou02.enet.dec.com> Date: 7 Aug 90 07:55:48 GMT References: <7206@helios.TAMU.EDU> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 24 In article <7206@helios.TAMU.EDU> jdm5548@diamond.tamu.edu (James Darrell McCauley) writes: >main() { > int *a,*b; Initially, a and b are NULL pointers (do not point to anything usable). > b=(int *)malloc( (unsigned) 4*sizeof(int)); Now b points to some storage that the program can use, and a is still null. > inita(a,b); Now b still points to some storage that the program can use, and a is still null. The null pointer in a was copied to inita's first argument. The useful pointer in b was copied to initb's second argument. Nothing was copied back. C function calls are call-by-value, not call-by-value-return, not call-by-reference. >} >inita (a,b) int a[],b[]; { > a=(int *)malloc( (unsigned) 4*sizeof(int)); This changes one of inita's variables from null to a useful pointer. Unfortunately, no one gives the useful pointer back to main. >} (Note to the FAQ list maintainer: Does the FAQ list mention call-by-value?) -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com This is me speaking. If you want to hear the company speak, you need DECtalk.