|
-
Mar 1st, 2001, 07:15 PM
#1
Thread Starter
Hyperactive Member
I have been confused about when exacly to use a pointer. When I write a program that needs to pass arguments I don't see the difference in just saying-- for example
char mystr;
or
char *mystr;
what is the difference?
Thanks
Matt 
-
Mar 1st, 2001, 07:50 PM
#2
Frenzied Member
char mystr; = the actual char
char *mystr; = the address of mystr
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Mar 1st, 2001, 08:01 PM
#3
Frenzied Member
When you're passing parameters in functions with C, the parameters are passed by value (as opposed to by reference). This means that the variables holding the incoming parameters in a functions are copies of the original values, and you can't change the original values.
However, if you pass in a pointer to a variable that contains a value, then what is passed in is the address. This address is still the address of the variable containing the value, and if you change that value then you change the original variable. This means you can pass in variables by reference.
Actually, to truly pass by reference (passing a pointer still copies the value of the address) you need to use C++, when you can actually pass references.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|