SIMPLE malloc & pointer question
diamond@tkovoa
diamond at tkou02.enet.dec.com
Tue Aug 7 17:55:48 AEST 1990
In article <7206 at helios.TAMU.EDU> jdm5548 at 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 at tkou02.enet.dec.com
This is me speaking. If you want to hear the company speak, you need DECtalk.
More information about the Comp.lang.c
mailing list