Results 1 to 6 of 6

Thread: Passing function arguments by refrence

  1. #1

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Resolved Passing function arguments by refrence

    In C.

    When you declare your function prototypes and you want to pass the argument values by refrence, do you have to use the indirection operator in the argument definition list? I haven't really done work with pointers for a while and I can't remember...

    Also I wanted to know that since the memory address of an array just points to the first address in a contigous segment of addresses for each element, why is it that you can't access the memory addresses for the array elements other than the first one? And if you can, how can you do it?
    Last edited by GamerMax5; Jan 17th, 2006 at 06:16 PM.

  2. #2
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: Passing function arguments by refrence

    There's no pass by reference in C
    In C there's only pass by Value
    In C++ there's only pass by value and pass by reference
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  3. #3
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: Passing function arguments by refrence

    The only way to pass by reference in C is to use pointers.
    The address of the second element of an array can be written a + 1 or &a[1]

  4. #4

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: Passing function arguments by refrence

    Thanks twanvl. I didn't think about that. lol

    So then using your example, every array element past the first one's can be accessed by incrementing the current element. Thx.

    BTW... *slaps sunnypalsingh* Just kidding.
    Last edited by GamerMax5; Jan 17th, 2006 at 06:20 PM.

  5. #5
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: Passing function arguments by refrence

    Quote Originally Posted by GamerMax5
    BTW... *slaps sunnypalsingh* Just kidding.
    May I know what made you say so
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: Passing function arguments by refrence

    Feel free to PM eachother if you have an issue, but we don't need it in this forum.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

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