Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!wa4mei!kd4nc!trantext!brian
From: brian@trantext.UUCP (Brian Bainter)
Newsgroups: comp.lang.c
Subject: Re: passing *char parameters by reference
Message-ID: <180@trantext.UUCP>
Date: 10 Aug 89 19:17:03 GMT
References: <1424@novavax.UUCP>
Distribution: usa
Organization: TranstexT (ICS Atlanta GA.)
Lines: 36

In article <1424@novavax.UUCP>, gls@novavax.UUCP (Gary Schaps) writes:
> Would someone be kind enough to tell me why this program fails?
> 
> char *x, *y;
> {
[code to swap strings deleted]
> }
> 
> main()
> {
>    char *a="aaaa";
>    char *b="bbbb";
> 
>    swap( &a, &b );
>    printf( " a = %s\t b = %s\n", a, b);
> }



What you are trying unsuccessfully to do here, if I am not mistaken, is to
swap what a and b point to. If this is the case, then leave off the ampersands
(&) from the swap call. What you are doing wrong here is trying to pass the
address of the pointers a and b to swap instead of the addresses that a and
b point to. Remember that a and b are pointers and therefore have addresses
themselves. When you use the ampersand with a variable (pointer or otherwise)
you will be working with the address of that particular variable.



Hope this helps,

-- 

Brian R. Bainter  KA7TXA
gatech!kd4nc!trantext!brian or
gatech!tomcat!brian