www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/17/07:00:48

From: Robert vd Boon <rjvdboon AT cs DOT vu DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Question about pass by pointer
Date: 17 Sep 1998 10:46:16 GMT
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Lines: 41
Message-ID: <6tqp9o$j7i$1@star.cs.vu.nl>
References: <3600c4ec DOT 1308545 AT news DOT hknet DOT com>
NNTP-Posting-Host: sloep102.cs.vu.nl
User-Agent: tin/pre-1.4-980730 (UNIX) (SunOS/5.5.1 (sun4u))
Originator: rjvdboon AT sloep102 DOT cs DOT vu DOT nl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"four 8bit characters, chinese?)" <h2owong AT hknet DOT com> wrote:
> 	void change(char *n){ 
> 	    *n=70; 
> 	}
> 	int main(){
> 	    char Number=0;
> 	    printf("Number=%i\n",Number);
> 	    change(&Number);
> 	   printf("Number=%i\n",Number);
> 	   return 0;
> 	
> What I want to ask is that when the address of Number pass to function
> "change", the address value will store in var 'n' , but not '*n' ?!

Yes, with change(char *n) you declare a variable `n' which points to a
char. With `*n=70' in the body you say: dereference the pointer `n' (get
to the value stored at the address `n') and put 70 there.
If you want to know the address stored _in_ `n' you can say:
printf("address in n: 0x%p\n", n);
the address _of_ `n' say:
printf("address of n: 0x%p\n", &n);
in your change(char *n) function.

Get a book about C (and read it ;-))

> Damn, I don't know how to say it....... :(

Well, if you have managed to formulate your question more precisely,
ask again, but in another newsgroup (I suggest for this kind of
question comp.lang.c). Post here only for questions about
DJGPP/problems with things compiled with DJGPP/compiling with
DJGPP/contributions using DJGPP.

hth,
 Robert.

[1] (would char* n be clearer for you? If so, remember that char* n, j;
     declares a pointer to a char `n', and a char `j')
-- 
rjvdboon AT cs DOT vu DOT nl        | "En dat is niet waar!" sprak ex-Staatsecretaris-
www.cs.vu.nl/~rjvdboon   |    van-Onderwijs Netelenbos fel.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019