linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* efficiency in passing a value to a function
@ 2007-04-04 17:13 Shriramana Sharma
  2007-04-04 18:27 ` Glynn Clements
  2007-04-04 18:38 ` Steve Graegert
  0 siblings, 2 replies; 11+ messages in thread
From: Shriramana Sharma @ 2007-04-04 17:13 UTC (permalink / raw)
  To: linux-c-programming

Hello.

Is providing an input to a function by constant reference more efficient 
than passing it by value? In what way.

For ex:

int addOne ( const & int inValue ) { return inValue + 1 ; }

vs:

int addOne ( int inValue ) { return inValue + 1 ; }

or:

void printThis ( const & int inValue ) { cout << inValue ; }

vs:

void printThis ( int inValue ) { cout << inValue ; }

I think passing as const & would be more efficient since passing by 
value would involve copying the value whereas passing by const & would 
skip this step. Am I right? Or is there something else?

Thanks in advance.

Shriramana Sharma.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-04-14 13:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-04 17:13 efficiency in passing a value to a function Shriramana Sharma
2007-04-04 18:27 ` Glynn Clements
2007-04-11 21:44   ` Adam Dyga
2007-04-04 18:38 ` Steve Graegert
2007-04-05 12:05   ` Glynn Clements
2007-04-05 13:02     ` Steve Graegert
2007-04-08 15:17       ` Shriramana Sharma
2007-04-13 17:23         ` Glynn Clements
2007-04-14 13:15         ` Adam Dyga
2007-04-08 14:45   ` Shriramana Sharma
2007-04-13 17:51     ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).