Mail Archives: djgpp/1998/09/17/07:00:48
"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 -