Tuesday, February 9, 2010

C++ function (Passing by ???)

Passing by value
void func(int a){}

Advantage
Leave argument untouched

Disadvantage
Create an extra copy -> can consume more time

Passing by reference
void func(int& a){}

Advantage
No extra copy created

Disadvantage
Alters the argument variable, can be dangerous if not used with caution
(cf. http://iagtm.blogspot.com/2011/06/quant-interview-questions-model_10.html)

Pointer (C legacy?)
void func(int* a){}

No comments:

Post a Comment