c++ - Using variables versus pointers to variables as parameters for a function -
when function requires pointer argument (and not variable pointer references), because of size of values passed function?
i can understand how want pass pointer array or struct, rather passing entire array or struct, other reasons decision? example, function requiring pointer int
(4 bytes) rather int
(4 bytes) itself.
if function change value of parameter (such int
), must pass in pointer it. otherwise, changes function makes made on copy.
in general, so-called "output parameters" in c , c++ pointers whatever variable affected function.
as arrays, c doesn't permit 1 pass large block of memory function, , have no choice pass pointer.
(edit: discussed in comments, answer applies pointers only. in c++, 1 may use references)
Comments
Post a Comment