What is the advantage of using a pointer to a structure as a parameter to a function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • needhlp2
    New Member
    • Aug 2007
    • 2

    What is the advantage of using a pointer to a structure as a parameter to a function?

    What is the advantage of using a pointer to a structure as a parameter to a funtion, instead of the structure itself?
    -the code is easier to read

    -it is more efficient because the structure is not copied

    -there is no difference; it is a matter of style

    -passing a structure as a parameter is not allowed
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by needhlp2
    What is the advantage of using a pointer to a structure as a parameter to a funtion, instead of the structure itself?
    -the code is easier to read

    -it is more efficient because the structure is not copied

    -there is no difference; it is a matter of style

    -passing a structure as a parameter is not allowed
    What programming language are you talking about? C? C++? If so, you'd better
    ask that question in the C/C++ forum.

    kind regards,

    Jos

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Sounds like a homework question to me. If so, please check out our Posting Guidelines. Thanks.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Changed thread title to better describe the problem.

        Moving to the C forum.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          You use a pointer to a structure as a funciton arguiment rather than the structure itself to a) let the called function modify the variable in the calling function, b) avoid making a copy of the struct variable.

          Making copies takes time and if the struct is large, it eats memory. Copies also involve considerations of "deep copy" versus "shallow copy".

          Comment

          Working...