By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

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

P: 2
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
Aug 5 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 10K+
P: 11,448
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
Aug 5 '07 #2

bartonc
Expert 5K+
P: 6,596
Sounds like a homework question to me. If so, please check out our Posting Guidelines. Thanks.
Aug 5 '07 #3

pbmods
Expert 5K+
P: 5,821
Changed thread title to better describe the problem.

Moving to the C forum.
Aug 5 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
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".
Aug 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.