0

Passing values as const reference in function arguments is necessary to avoid creating copies for large objects. Since built-in types like int and bool are a few bytes in size, do we need to pass them by reference?

nac001
  • 693
  • 2
  • 9
  • 18
  • 3
    Maybe it matters. Maybe it doesn't. To determine if it matters for you code, you will need to **profile** your optimized code, and determine if one or the other approach is a material improvement in performance. – Eljay Feb 10 '22 at 14:10
  • 1
    It is better to pass them by value. The compiler *might* optimise a (`const`) ref, but then again it might not and have to generate an extra dereference. – Paul Sanders Feb 10 '22 at 14:16

0 Answers0