Re: Passing pointers?
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 21 Dec 2007 17:55:00 -0800
I have several introductory C books Brian. None of which show this type of
example, unfortunately!
I am currently finishing up several aspects of my project. And as soon as I
have a chance Brian, I will go out and *carefully* choose a better C book
then the ones I have. I appreciate your concern! :)
Therefore the required parameter in:
y(*a); //Is this correct??? I doubt it!
is a pointer of integer type "int*", which contains an address.
I could be wrong, but I believe this is it???
==============================
void x(int *a)
{
y(a); //"a" contains an address.
}
void y(int *b)
{
int x;
x=*b; //99 should be assigned to x.
}
void main()
{
int z=99;
x(&z);
}
===================================
If you still feel like replying back, let me know!
Thankyou for getting back!
--
Best regards
Robert
"Brian Muth" wrote:
.
"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:29A7E439-7BD1-4142-AD5C-DBCD484A0591@xxxxxxxxxxxxxxxx
Hello,`
I am wondering when passing a pointer to a function and require to further
pass it to another funtion (two functions deep), can we re-pass the pointer
to the second function using the "*" ?
Basically wrong values are displayed when dereferencing b in y function.
here is an example :
====================================
void x(int *a)
{
y(*a); //Is this correct??? I doubt it!
}
"a" is an int*
"*a" is an int
Therefore you are trying to pass an "int" as a parameter. Which is wrong, since the required parameter is "int*".
As an aside, have you bought yourself an introductory book on C as I have suggested?
Brian
- Follow-Ups:
- Re: Passing pointers?
- From: Brian Muth
- Re: Passing pointers?
- From: Abhishek Padmanabh
- Re: Passing pointers?
- References:
- Passing pointers?
- From: Robby
- Re: Passing pointers?
- From: Brian Muth
- Passing pointers?
- Prev by Date: Re: A question about IShellLink interface and the COM object.
- Next by Date: Re: Reversing a String
- Previous by thread: Re: Passing pointers?
- Next by thread: Re: Passing pointers?
- Index(es):
Relevant Pages
|