Results 1 to 3 of 3

Thread: pointers and charaters

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Unhappy

    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

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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


  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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
  •  



Click Here to Expand Forum to Full Width