0

I know the difference between pass by value and pass by reference. I use them and understand how they work in the codes that I've dealt so far. However, I'm looking for a general rule. What is generally the best time to use pointers and what is the best to use actual values? Examples are much appreciated.

mfaieghi
  • 570
  • 2
  • 9
  • 24

1 Answers1

4

As a general rule, pass-by-value for basic types (int, char, etc.), and pass-by-pointer (or better, pass-by-reference) for big data as struct.

Thinking of a struct with 1000 data members, and the cost to copy that gigantic data to a function. It'd be much quicker to pass-by-pointer or pass-by-reference in that case.

artm
  • 17,291
  • 6
  • 38
  • 54